gpt4 book ai didi

python - 使用 Python 请求的重定向错误太多

转载 作者:行者123 更新时间:2023-11-28 20:27:44 24 4
gpt4 key购买 nike

HTTP 请求在我的本地主机上运行良好,但在我的服务器上使用 python 请求库运行相同的 HTTP 请求会返回“太多重定向”错误

当我进入

localhost/terminal/jfk

在浏览器中,我得到了预期的 json 字典。

但是,当我使用服务器上的 python 请求库在 python 中运行以下命令时

requests.get('http://splitmyri.de/terminal/jfk')

我从请求模块收到“太多重定向”错误。

关于导致错误的原因有什么想法吗?或者缩小潜在原因的建议?

最佳答案

阿莎,

在您回复说这确实是您的网站后,我检查了为什么我的 GoDaddy.com 页面是空的。问题是您的 splitmyri.de DNS 条目返回了两个不同的 A 记录...

分析结果,使用107.10.141.119:
在我的 /etc/hosts 文件中硬编码 107.10.141.119 splitmyri.de 允许我查询 107.10.141.119,它在 中返回“这是我的网站” >index.html(然后我检查了 http://splitmyri.de/terminal/ 并得到了一个空的 json 散列,mime 类型 = [application/json])。检查此地址的反向条目会返回一个 Amazon AWS 主机(我期望真实网页的那种条目)。现在您上面的代码按预期工作...

[mpenning@Bucksnort ~]$ python
Python 2.5.2 (r252:60911, Jan 24 2010, 14:53:14)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.get('http://splitmyri.de/terminal/')
<Response [200]>
>>> requests.get('http://splitmyri.de/terminal/').content
u'{}'
>>> # requests.get('http://splitmyri.de/terminal/jfk').content returns a huge json hash

使用68.178.232.100分析结果:
对 68.178.232.100 执行相同的查询得到一个空的 GoDaddy.com 页面。反向映射此地址会出现一个典型的停放域条目。在此处发送请求会返回 TooManyRedirects,如您在尝试中看到的那样...

[mpenning@Bucksnort ~]$ python
Python 2.5.2 (r252:60911, Jan 24 2010, 14:53:14)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> foo = requests.get('http://splitmyri.de/terminal/jfk')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.linux-i686/egg/requests/api.py", line 50, in get
File "build/bdist.linux-i686/egg/requests/api.py", line 37, in request
File "build/bdist.linux-i686/egg/requests/sessions.py", line 170, in request
File "build/bdist.linux-i686/egg/requests/models.py", line 383, in send
File "build/bdist.linux-i686/egg/requests/models.py", line 210, in _build_response
requests.exceptions.TooManyRedirects
>>>

解决方案:
为 splitmyri.de 修复您的 DNS(删除 68.178.232.100 的 A 记录),一切都会好的。

包括以下 DNS 信息作为 FYI...

[mpenning@Bucksnort ~]$ dig splitmyri.de

; <<>> DiG 9.6-ESV-R4 <<>> splitmyri.de
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 54051
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 2, ADDITIONAL: 4

;; QUESTION SECTION:
;splitmyri.de. IN A

;; ANSWER SECTION:
splitmyri.de. 3193 IN A 68.178.232.100
splitmyri.de. 3193 IN A 107.20.141.119

;; AUTHORITY SECTION:
splitmyri.de. 3193 IN NS ns49.domaincontrol.com.
splitmyri.de. 3193 IN NS ns50.domaincontrol.com.

;; ADDITIONAL SECTION:
ns49.domaincontrol.com. 3193 IN A 216.69.185.25
ns49.domaincontrol.com. 3193 IN AAAA 2607:f208:206::19
ns50.domaincontrol.com. 3193 IN A 208.109.255.25
ns50.domaincontrol.com. 3193 IN AAAA 2607:f208:302::19

;; Query time: 1 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed Oct 26 05:14:51 2011
;; MSG SIZE rcvd: 205

[mpenning@Bucksnort ~]$
[mpenning@Bucksnort ~]$ dig -x 107.20.141.119

; <<>> DiG 9.6-ESV-R4 <<>> -x 107.20.141.119
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41049
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 6, ADDITIONAL: 6

;; QUESTION SECTION:
;119.141.20.107.in-addr.arpa. IN PTR

;; ANSWER SECTION:
119.141.20.107.in-addr.arpa. 300 IN PTR ec2-107-20-141-119.compute-1.amazonaws.com.

;; AUTHORITY SECTION:
141.20.107.in-addr.arpa. 900 IN NS pdns1.ultradns.net.
141.20.107.in-addr.arpa. 900 IN NS pdns2.ultradns.net.
141.20.107.in-addr.arpa. 900 IN NS pdns3.ultradns.org.
141.20.107.in-addr.arpa. 900 IN NS pdns5.ultradns.info.
141.20.107.in-addr.arpa. 900 IN NS pdns4.ultradns.org.
141.20.107.in-addr.arpa. 900 IN NS pdns6.ultradns.co.uk.

;; ADDITIONAL SECTION:
pdns1.ultradns.net. 86400 IN A 204.74.108.1
pdns1.ultradns.net. 86400 IN AAAA 2001:502:f3ff::1
pdns2.ultradns.net. 86400 IN A 204.74.109.1
pdns3.ultradns.org. 86400 IN A 199.7.68.1
pdns4.ultradns.org. 86400 IN A 199.7.69.1
pdns4.ultradns.org. 86400 IN AAAA 2001:502:4612::1

;; Query time: 306 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed Oct 26 05:09:47 2011
;; MSG SIZE rcvd: 392

[mpenning@Bucksnort ~]$ dig -x 68.178.232.100

; <<>> DiG 9.6-ESV-R4 <<>> -x 68.178.232.100
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 38578
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2

;; QUESTION SECTION:
;100.232.178.68.in-addr.arpa. IN PTR

;; ANSWER SECTION:
100.232.178.68.in-addr.arpa. 3600 IN PTR parkwebwin-v01.prod.mesa1.secureserver.net.

;; AUTHORITY SECTION:
232.178.68.in-addr.arpa. 3600 IN NS cns1.secureserver.net.
232.178.68.in-addr.arpa. 3600 IN NS cns2.secureserver.net.

;; ADDITIONAL SECTION:
cns1.secureserver.net. 3600 IN A 208.109.255.100
cns2.secureserver.net. 3600 IN A 216.69.185.100

;; Query time: 173 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed Oct 26 05:12:06 2011
;; MSG SIZE rcvd: 171

[mpenning@Bucksnort ~]$

关于python - 使用 Python 请求的重定向错误太多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7896842/

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