From docs to urllib.request.urlopen:
urllib.request.urlopen(url[, data][, timeout])
Open the URL url, which can be either a string or a Request object.
If it urllib.request.urlopendoes not receive the string, it is assumed that this is a Request object. You are passing a byte connection, so it does not work, for example:
>>> a = urllib.request.urlopen('http://www.google.com').read()
>>> a = urllib.request.urlopen(b'http://www.google.com').read()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/request.py", line 153, in urlopen
return opener.open(url, data, timeout)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/request.py", line 446, in open
req.timeout = timeout
AttributeError: 'bytes' object has no attribute 'timeout'
To fix this, convert your bytestring back to str, decode it with the appropriate codec:
>>> a = urllib.request.urlopen(b'http://www.google.com'.decode('ASCII')).read()
Or do not use intestrings in the first place.