urlretrieve 返回类型错误 [英] urlretrieve returning typeerror

查看:28
本文介绍了urlretrieve 返回类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么我的代码会返回这个错误,我似乎无法调试它.

I don't know why my code is returning this error, I can't seem to debug it.

TypeError: 预期的字符串或类似字节的对象

这是我用来下载的

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)

推荐答案

urlretrieve 似乎不允许发送标头.

It appears that urlretrieve doesn't allow the sending of headers.

你得到的错误是因为 urlretrieve 期望那里有一个 URL 而不是 Request 对象.

And the error you're getting is because urlretrieve is expecting a URL there and not a Request object.

由于它是您自己的网络服务器,因此您要向其发送请求,也许您可​​以修改其配置以接受那些没有标头的 urlretrieve 请求.

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.

祝你好运.

这篇关于urlretrieve 返回类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆