簡體   English   中英

請求中的參數(Python)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM