【问题标题】:Why does this program throw errors?为什么这个程序会抛出错误?
【发布时间】:2023-04-05 22:18:01
【问题描述】:

我昨天使用的是同一个程序,它应该打开浏览器并在那里插入我们的查询。昨天运行良好。今天它抛出错误。

from googlesearch import *
import webbrowser
#to search, will ask search query at the time of execution
query = input("Input your query:")
for url in search(query, tld="co.in", num=1, stop = 1, pause = 2):
    webbrowser.open("https://google.com/search?q=%s" % query)'

这是我得到的错误:

Traceback (most recent call last):
  File "C:/Users/DELL/AppData/Local/Programs/Python/Python37-32/arehojayaar.py", line 5, in <module>
    for url in search(query, tld="co.in", num=1, stop = 1, pause = 2):
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python37-32\lib\site-packages\googlesearch\__init__.py", line 288, in search
    html = get_page(url, user_agent)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python37-32\lib\site-packages\googlesearch\__init__.py", line 154, in get_page
    response = urlopen(request)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python37-32\lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python37-32\lib\urllib\request.py", line 531, in open
    response = meth(req, response)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python37-32\lib\urllib\request.py", line 641, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python37-32\lib\urllib\request.py", line 563, in error
    result = self._call_chain(*args)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python37-32\lib\urllib\request.py", line 503, in _call_chain
    result = func(*args)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python37-32\lib\urllib\request.py", line 755, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python37-32\lib\urllib\request.py", line 531, in open
    response = meth(req, response)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python37-32\lib\urllib\request.py", line 641, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python37-32\lib\urllib\request.py", line 569, in error
    return self._call_chain(*args)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python37-32\lib\urllib\request.py", line 503, in _call_chain
    result = func(*args)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python37-32\lib\urllib\request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 429: Too Many Requests

【问题讨论】:

  • 您尝试发出多少请求?连续多快?

标签: python http url


【解决方案1】:

您收到HTTP Error 429: Too Many Requests,这意味着您向端点发出了太多请求,而服务器决定对您进行速率限制。你必须等到你被允许再次提出请求。

【讨论】:

  • 不,错误不会告诉您它将持续多长时间,因此无法知道。也许明天试试。
  • 像这样轰炸服务器并不好。服务器配置将确定您的 IP 被阻止多长时间,但如果您重新运行此程序而不限制您的请求率,您将再次被阻止。
  • 那么我应该怎么做才能限制请求率有什么建议吗?
  • 查看您当前的代码,我将删除 search() 和 for 循环,因为您没有使用结果,您只需使用搜索查询打开谷歌搜索。
  • 嘿,没有给出“HTTP Error 429: Too Many Requests”错误,谢谢,我很高兴!
猜你喜欢
  • 2019-09-01
  • 1970-01-01
  • 2021-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多