0

PythonモジュールRequestsでGETリクエストを行うと、奇妙なURLになります:

>>> 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"

この URL はエラー 400 で終了します。しかし、同じ URL に RestKit を使用すると、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"

リクエストの問題は何ですか?

4

2 に答える 2

2

最新のタグ付きリリースではなく、https://github.com/kennethreitz/requests.gitから現在のマスター ブランチをインストールすると、正しく動作します。

Requests は、最後の 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

これは最新の Requests リリース (0.10.1) で再現できますが、未リリースのマスター (および開発) ブランチでは修正されているようです。

このバグを修正したコミットはhttps://github.com/kennethreitz/requests/commit/cb64d311719e627df0f78c8446d40326899206c3でした

于 2012-01-31T13:14:10.353 に答える
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
于 2012-01-31T12:50:47.837 に答える