[英]Params in requests (python)
我有以下網址:
url = 'http://api.worldweatheronline.com/premium/v1/weather.ashx?key=KEY_VALUE&q=48.85,2.35&num_of_days=2&tp=3&format=json'
我想使用requests
Python
庫進行訪問。 如果我將其作為url插入,則它確實會返回預期的數據( requests.get(url)
)。 嘗試使用params
參數進行連接時出現我的問題。 我的方法是以下方法:
urlPrefix = 'http://api.worldweatheronline.com/premium/v1/weather.ashx'
parameters = {'key': key, 'q': {48.85,2.35}, 'num_of_days':2, 'tp': 3, 'format': 'json'}
print(requests.get(urlPrefix, params=parameters).url)
>>> http://api.worldweatheronline.com/premium/v1/weather.ashx?key=KEY_VALYE&tp=3&q=48.85&q=2.35&format=json&num_of_days=2
如您所見,由於{48.85,2.35}
的表示形式,URL將有所不同。 因此,我的問題是: q
值應如何表示以具有與第一個請求相同的url請求?
對於q表示,最好將整個內容分組為一個字符串。 即'q':{'48.85,2.35'}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.