gpt4 book ai didi

python - 请求 Python 中的 url 超出了最大重试次数

转载 作者:行者123 更新时间:2023-12-02 02:27:22 25 4
gpt4 key购买 nike

我尝试向此 URL 发送请求:Site URL

并使用以下代码进行简单的页面阅读:

import requests
url_1 = 'http://www.dsit.org.ir/?cmd=page&Cid=92&title=Kontakt&lang=fa'
print(requests.get(url_1).text)

但是我得到这个错误:

requests.exceptions.ConnectionError: HTTPConnectionPool(host='www.srgfesrsergserg.com', port=80): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000008EC69AAA90>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

这个网站非常基础,没有特殊的安全措施。另外,我只请求了一次

一切都很好,我用 Request-html 很容易打开这个页面,但我不知道这里有什么问题!

最佳答案

添加标题。

伪装浏览器。

import requests

headers = {
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36'}

url_1 = 'http://www.dsit.org.ir/?cmd=page&Cid=92&title=Kontakt&lang=fa'

print(requests.get(url=url_1, headers=headers).text)

关于python - 请求 Python 中的 url 超出了最大重试次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65448909/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com