0

I'm running a snippest like that:

p = re.compile(b'^((?!-)[*A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,6}$')
m = p.match(domain)

'domain' are the ip addresses get from google dns. I know there is something wrong with the decoding, so I've tried to encode the regular expressions after it was compiled, but still get the bug notice like this,

Traceback (most recent call last):
File "D:\python34\lib\threading.py", line 921, in _bootstrap_inner
self.run()
File "update.py", line 101, in run
  if validate_domain(domain):
File "update.py", line 182, in validate_domain
  m = pattern.match(domain)
TypeError: can't use a bytes pattern on a string-like object

Could you give me some tips for this situation

!!!Programming language: python 3.4

1 Answers1

1

Appending a b to the start of your pattern makes it a bytes object. But you can't match string objects with a bytes pattern. The error is quite clear:

p = re.compile(b'^((?!-)[*A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,6}$')
#              ^

You probably intended to use r''

Moses Koledoye
  • 77,341
  • 8
  • 133
  • 139