詞典有否固定的順序。在參數傳遞作爲(key, value)
雙序列代替,如果您需要訂購參數:
qparams = (
('cli', 10),
('url', 'www.google.com'),
)
你也應該從URL離開關?
,requests
會處理,對於你。
演示:
>>> import requests
>>> endpoint = 'http://data.alexa.com/data'
>>> qparams = (
... ('cli', 10),
... ('url', 'www.google.com'),
...)
>>> response = requests.get(endpoint, params=qparams)
>>> response.url
u'http://data.alexa.com/data?cli=10&url=www.google.com'
>>> print response.content
<?xml version="1.0" encoding="UTF-8"?>
<ALEXA VER="0.9" URL="google.com/" HOME="0" AID="=" IDN="google.com/">
<KEYWORDS>
<KEYWORD VAL="Mountain View"/>
</KEYWORDS><DMOZ>
<SITE BASE="google.com/" TITLE="Google" DESC="Enables users to search the world's information, including webpages, images, and videos. Offers unique features and search technology.">
<CATS>
<CAT ID="Top/Computers/Internet/Searching/Search_Engines/Google" TITLE="Search Engines/Google" CID="374822"/>
<CAT ID="Top/Regional/North_America/United_States/California/Localities/M/Mountain_View/Business_and_Economy/Industrial/Computers_and_Internet" TITLE="Industrial/Computers and Internet" CID="625367"/>
<CAT ID="Top/World/Français/Informatique/Internet/Recherche/Moteurs_de_recherche/Google" TITLE="Moteurs de recherche/Google" CID="247347"/>
<CAT ID="Top/World/Arabic/إقليمـي/الشرق_الأوسط/السعودية/تجارة_و_أقتصاد/كمبيوتر_و_إنترنت/محركات_بحث" TITLE="كمبيوتر و إنترنت/محركات بحث" CID="204954"/>
<CAT ID="Top/World/Español/Informática/Internet/Buscando_en_Internet/Motores_de_búsqueda" TITLE="Buscando en Internet/Motores de búsqueda" CID="29498"/>
</CATS>
</SITE>
</DMOZ>
<SD>
<POPULARITY URL="google.com/" TEXT="1" SOURCE="panel"/>
<REACH RANK="1"/>
<RANK DELTA="+0"/>
<COUNTRY CODE="US" NAME="United States" RANK="1"/>
</SD>
</ALEXA>
參數字典...詞典沒有命令......這個網站需要它們按照一定的順序其實是對他們的一部分 –
設計窮人和問題後的URL部分標記只指定了get參數,所以訂單無關緊要 – fedorSmirnov
@fedorSmirnov,如果您檢查兩個鏈接,順序顯然很重要。一個作品,一個不 – mhlester