[英]Python - requests lib - error ('Connection aborted.', BadStatusLine(“''”,))
I have an issue with requests lib : With a code like 我在请求lib时遇到问题:使用类似的代码
requests.get("HTTPS://api.twitch.tv/helix/...", headers = headers)
, requests.get("HTTPS://api.twitch.tv/helix/...", headers = headers)
,
with the information that twitch API needs in the variable "headers". 在变量“标头”中包含抽搐API所需的信息。
And unfortunately, with except Exception, e: print(e)
I get ('Connection aborted.', BadStatusLine("''",))
. 不幸的是,
except Exception, e: print(e)
我得到的是except Exception, e: print(e)
('Connection aborted.', BadStatusLine("''",))
。
I already tried to fake my user agent. 我已经尝试伪造我的用户代理。
I'm almost sure that it isn't from server (Twitch) because I also use the ancient API and I have the same bug, while I already used it successfully (Since that, I reseted my Raspberry, it may can explain...). 我几乎可以确定它不是来自服务器(Twitch),因为我也使用了古老的API,并且在我已经成功使用它的情况下也遇到了相同的错误(因此,我重置了Raspberry,它可以解释。 )。
It doesn't do this error every requests, but like 1 on 10 so it's a bit embarrassing. 它不会在每个请求中都执行此错误,但是就像10上的1一样,这有点尴尬。
I also have this error only with Raspbian, but not with Windows. 我也只有Raspbian有此错误,而Windows没有。
Thanks for helping me, a young lost coder. 感谢您的帮助,一个年轻的失落编码员。
There are a lot of reasons for this error and main of them is - you violate Twitch's user policy (which directly prohibit using scrapers) and server banned some of your requests. 造成此错误的原因有很多,主要的原因是-您违反了Twitch的用户政策(直接禁止使用抓取工具),并且服务器禁止了您的某些请求。
You should try to use sessions when you access site: 访问网站时,您应该尝试使用会话:
session = requests.Session()
and use session.get
instead of requests.get
并使用
session.get
而不是requests.get
Another things to try are limit your requests rate and rotate different sessions with different headers (don't mix headers and sessions). 要尝试的另一件事是限制您的请求速率,并使用不同的标题旋转不同的会话(不要混合标题和会话)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.