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