urlretrieve returning typeerror

僤鯓⒐⒋嵵緔 提交于 2019-12-11 08:54:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!