2015-09-26 49 views
0

我正在試圖製作一個程序,請求蒸汽以獲得物品的最便宜的價格。爲此,我將使用StatTrak™P250 |超新星(Factory New)爲例。unicode中的Python請求

的問題是,當請求,你會做出一個網址:

http://www.steamcommunity.com/market/priceoverview/?country=SG&currency=13&appid=730&market_hash_name=StatTrak™%20P250%20%7C%20Supernova%20%28Factory%20New%29 

之後,(我用的請求模塊),我這樣做:

url = "http://www.steamcommunity.com/market/priceoverview/?country=SG&currency=13&appid=730&market_hash_name=StatTrak™%20P250%20%7C%20Supernova%20%28Factory%20New%29" 
requests.get(url) 

但是,服務器會返回一個錯誤。

我似乎無法找到取代™的解決方案。我試過%2122。在python中,我嘗試使用u'\u084a',但那不起作用。問題是python在請求中直接發送\u084a。有什麼辦法可以解決這個問題嗎?

+0

您需要正確編碼和引用參數;看到重複。 –

回答

2

只需使用URL編碼。你不能在網址中使用unicode。

>>> import urllib 
>>> f = {'market_hash_name': 'StatTrak™'} 
>>> urllib.urlencode(f) 
'market_hash_name=StatTrak%E2%84%A2' 

也有可能

>>> urllib.quote_plus('StatTrak™')