使用Python请求执行Google搜索时接收429返回代码
我正在尝试使用请求库在Python中执行简单的Google搜索。他们查询,标题和请求如下:
query = 'https://www.google.com/search?q=search+term&ie=utf-8'
header = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15'}
resp = requests.get(query, headers=header)
从我的笔记本电脑执行时,代码成功运行(MacBook Pro运行MacOS Monterey和Python 3.9)。但是,我使用的是托管提供商,需要从服务器运行相同的代码。当我尝试执行搜索时,我会从Google那里获得429错误。我知道这通常表明提交了太多请求,但是单个请求发生。感觉好像有些环境正在发生,但是我不确定如何解决它。
更新:我尝试使用几个不同的代理,并获得了相同的结果(429返回代码)。
I'm attempting to execute a simple Google search in Python using the requests library. They query, header and request are shown below:
query = 'https://www.google.com/search?q=search+term&ie=utf-8'
header = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15'}
resp = requests.get(query, headers=header)
The code runs successfully when executed from my laptop (MacBook Pro running macOS Monterey and Python 3.9). However, I'm using a hosting provider and need to run this same code from a server. When I attempt to execute the search I get a 429 error from Google. I understand that this would normally indicate too many requests are being submitted, but it happens with a single request. It feels like there's something environmental going on, but I'm unsure as to how to address it.
Update: I tried using a couple of different proxies and got the same result (429 return code).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已发送了很多要求。看,您的问题是重复:
https://stackoverflow.com/questions/56758333/5675833/5675833/56758333/eror-429-with-simple-query-query-query-google-google-with - requests-python#:〜:text =%20HTTP%20429%20too%20many,%20making%20A%20A%20new%20报。
希望这会有所帮助。
那里有1个家伙说,问题是饼干。您必须保存它们,并按照下一个请求添加它们。
You've sended to much Requests. Look here, your Question is an Duplicate:
https://stackoverflow.com/questions/56758333/error-429-with-simple-query-on-google-with-requests-python#:~:text=The%20HTTP%20429%20Too%20Many,before%20making%20a%20new%20request.
Hope this Helps.
1 Guy there said, the Problem are Cookies. You have to Save them and add them by the next Request.