我正在運行一個 Python 腳本,它使用值列表作為 API 端點上的 HTTP 請求的查詢參數。這里有一個快照:df = pd.read_excel('grp.xlsx', sheet_name='Sheet1', usecols="A")for item in df.PLACE: df.PLACE.head() #1st level request def wbsearchentities_q(**kwargs): params = { 'action': 'wbsearchentities', 'format': 'json', 'language': 'en', 'search': item } params.update(kwargs) response = requests.get(API_ENDPOINT, params=params) return response r = wbsearchentities_q(ids=item) item_id = (r.json()['search'][0]['id']) item_label = (r.json()['search'][0]['label']) 我遇到了這個錯誤:IndexError: list index out of range這意味著 API 端點無法識別我列表中的某些項目。我會跳過并繼續循環。我試圖修復使用它沒有結果。提前致謝。
添加回答
舉報
0/150
提交
取消