0

製作與Python模塊請求GET請求奇怪的url結束:Python的請求模塊結束了奇怪的重定向

>>> import requests 
>>> r = requests.get("http://t.co/Uspy071j") 
>>> print r.url 
"http://feeds.feedburner.com/%257Er/LesArdoises/%257E3/bD2JuJagz5I/roxino-cest-tout-vert.html?utm_source=twitterfeed&utm_medium=twitter" 

這個網址有錯誤400結束,但使用RestKit對同一個URL時, final_url返回正確的值:

>>> import restkit 
>>> r = restkit.request("http://t.co/Uspy071j", follow_redirect=True) 
>>> print r.final_url 
"http://lesardoises.com/6277/roxino-cest-tout-vert.html?utm_medium=twitter&utm_source=twitterfeed" 

請求的問題是什麼?

+0

使用'curl'和以下三個'301'重定向,一些HTML終於取回。 – 2012-01-31 12:49:52

回答

0

在這裏工作:

In [6]: import requests 

In [7]: r = requests.get("http://t.co/Uspy071j") 

In [8]: r 
Out[8]: <Response [200]> 

In [9]: print r.url 
http://lesardoises.com/6277/roxino-cest-tout-vert.html?utm_medium=twitter&utm_source=twitterfeed 
2

如果從https://github.com/kennethreitz/requests.git而不是最新發布標籤安裝當前的主分支它會正常工作。

請求不正確地引用最後一個URL中的波浪線。而不是請求http://feedproxy.google.com/~r/LesArdoises/~3/bD2JuJagz5I/roxino-cest-tout-vert.html?utm_source=twitterfeed&utm_medium=twitter它請求http://feeds.feedburner.com/%257Er/LesArdoises/%257E3/bD2JuJagz5I/roxino-cest-tout-vert.html?utm_source=twitterfeed&utm_medium=twitter

我可以用最新的請求發佈(0.10.1)重現此,但它似乎是在未發佈的主(和開發)分支中修復。

的承諾是固定的這個bug是https://github.com/kennethreitz/requests/commit/cb64d311719e627df0f78c8446d40326899206c3