简体   繁体   English

Python-请求lib-错误(“连接已中止。”,BadStatusLine(“''”,))

[英]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.

相关问题 Python 请求获取 ('Connection aborted.', BadStatusLine("''",)) 错误 - Python Requests getting ('Connection aborted.', BadStatusLine("''",)) error Python Spider ConnectionError :(“连接已中止。”,BadStatusLine(“''”,)) - Python Spider ConnectionError: ('Connection aborted.', BadStatusLine(“''”,)) 连接已中止。',服务器上的BadStatusLine(“''”,)? - Connection aborted.', BadStatusLine(“''”,) on server? 当xml大小增加时,Python请求XML API异常ConnectionError :(“连接已中止。”,BadStatusLine(“''”,)) - Python Requests XML API Exception ConnectionError: ('Connection aborted.', BadStatusLine(“''”,)) when xml size increases 使用 python 请求获取 ('Connection aborted.', OSError(0, 'Error') 错误 - Getting ('Connection aborted.', OSError(0, 'Error') errors with python requests Python请求'连接中止。' 如果它将以cronjob开始 - Python requests 'Connection aborted.' if it will started with a cronjob Python requests.exception.ConnectionError:连接中止“BadStatusLine” - Python requests.exception.ConnectionError: connection aborted “BadStatusLine” 尝试发布到gfycat.com时,Python请求提供错误信息(“连接已中止。”,错误(“(104,'ECONNRESET')”,))) - Python requests giving error ('Connection aborted.', error(“(104, 'ECONNRESET')”,)) when attempting to post to gfycat.com python - requests.get(连接中止。',OSError(“(60,'ETIMEDOUT') - python - requests.get (Connection aborted.', OSError("(60, 'ETIMEDOUT') Python-requests [('连接中止。', TimeoutError(10060) ] - Python-requests [('Connection aborted.', TimeoutError(10060) ]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM