简体   繁体   English

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

[英]Too many redirects error using Python requests

HTTP requests are working fine on my localhost, but running the same HTTP requests using the python requests library on my server returns a "Too Many Redirects" error HTTP请求在我的localhost上工作正常,但是在我的服务器上使用python请求库运行相同的HTTP请求会返回“Too Many Redirects”错误

When I enter 当我进入

localhost/terminal/jfk

in a browser, I get a json dictionary as expected. 在浏览器中,我按预期获得了一个json字典。

However, when I run the following in python using the python requests library on my server 但是,当我在我的服务器上使用python请求库在python中运行以下内容时

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

I receive a "Too Many Redirects" error from the requests module. 我从请求模块收到“Too Many Redirects”错误。

Any thoughts as to what's causing the error? 是否有任何关于导致错误的想法? Or recommendations for narrowing potential causes? 或建议缩小潜在原因?

Asha, 阿莎,

After you responded that this really is your site, I checked out why I was getting an empty GoDaddy.com page. 在你回答这确实是你的网站后,我查看了为什么我得到一个空的GoDaddy.com页面。 The problem is that your DNS entry for splitmyri.de is returning two different A records... 问题是你的splitmyri.de的DNS条目返回两个不同的A记录...

Analyzing results, using 107.10.141.119 : 使用107.10.141.119分析结果
Hard coding 107.10.141.119 splitmyri.de in my /etc/hosts file allowed me to make queries to 107.10.141.119, which returns "this is my site" in index.html (then I checked http://splitmyri.de/terminal/ and got an empty json hash, with a mime type=[application/json]). 我的/etc/hosts文件中的硬编码107.10.141.119 splitmyri.de允许我对107.10.141.119进行查询,该查询在index.html返回“这是我的网站”(然后我检查了http://splitmyri.de/terminal /并得到一个空的json哈希,mime类型= [application / json])。 Checking the reverse entry for this address returns an Amazon AWS host (the kind of entry I expect for a real web page). 检查此地址的反向条目将返回Amazon AWS主机(我期望用于真实网页的条目类型)。 Now your code above works as expected... 现在您的代码按预期工作了......

[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 

Analyzing results using 68.178.232.100 : 使用68.178.232.100分析结果
Performing the same drill with queries to 68.178.232.100 gets an empty GoDaddy.com page. 对68.178.232.100的查询执行相同的钻取得到一个空的GoDaddy.com页面。 Reverse mapping this address turns up a typical entry for a parked domain. 反向映射此地址会显示停放域的典型条目。 Sending a request here returns TooManyRedirects as you saw in your attempts... 正如您在尝试中看到的那样,在此处发送请求会返回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
>>> 

SOLUTION : 解决方案
Fix your DNS for splitmyri.de (removing the A record for 68.178.232.100) and all will be good. 修复你的DNS for splitmyri.de(删除68.178.232.100的A记录),一切都会好的。

Including the DNS info below as an FYI... 包括下面的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 ~]$ 

If you need to narrow down the problem, a good idea is to use wireshark and analyse the different connections and their content. 如果您需要缩小问题范围,最好使用wireshark并分析不同的连接及其内容。 Like this you will see what is transferred over the wire. 像这样你会看到通过电线传输的是什么。 Good for debugging TCP related problems. 适合调试TCP相关问题。 Additionally, you may use the pdb Python module and debug your program. 此外,您可以使用pdb Python模块并调试您的程序。 Issue pdb.set_trace() right before the call, then single step into the function and see what it does. 在调用之前发出pdb.set_trace() ,然后单步执行该函数并查看它的作用。 More info about pdb can be found in the Python documentation or by pressing ? 有关pdb更多信息可以在Python文档中找到或按? .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python请求模块重定向过多的问题 - Issue with too many redirects with python requests module Python在网络抓取过程中请求太多重定向? - Python requests Too Many Redirects during web scraping? Python HTTP 错误 429(请求过多) - Python HTTP error 429 (Too Many Requests) Python:请求太多 - Python: Too many requests 尝试通过使用 Selenium 和 Python 的框架和 Javascript 的网页登录时出现 ERR_TOO_MANY_REDIRECTS 错误 - ERR_TOO_MANY_REDIRECTS error while trying to login through a webpage that uses frames and Javascript using Selenium and Python 如何使用 requests.post (Python) 发送数组? “值错误:解包的值太多” - How to send an array using requests.post (Python)? "Value Error: Too many values to unpack" 使用带有 Python 脚本的 Instagram API 时出现“429 错误:请求过多” - '429 error: too many requests' when using Instagram API with Python script Python:使用对重定向网页的请求 - Python: Using requests for a webpage that redirects 如何使用 Asyncio 避免错误 429(请求过多)python - How to avoid error 429 (Too Many Requests) python with Asyncio Scrapy内存错误(请求太多)Python 2.7 - Scrapy Memory Error (too many requests) Python 2.7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM