问题
I don't know why my code is returning this error, I can't seem to debug it.
TypeError: expected string or bytes-like object
Here is what I'm using to download
self.headers = { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' }
self.request = urllib.request.Request(url, headers=self.headers)
urllib.request.urlretrieve(self.request, reporthook=report)
回答1:
It appears that urlretrieve
doesn't allow the sending of headers.
And the error you're getting is because urlretrieve
is expecting a URL there and not a Request
object.
Since it's your own webserver you're sending the request to maybe you can modify its configuration to accept those urlretrieve
requests without headers.
Best of luck.
来源:https://stackoverflow.com/questions/43022570/urlretrieve-returning-typeerror