嗨,我正在基于Opensea API
生成随机的data to csv
文件。问题是我受到API上列表大小的限制。有没有办法绕过这个问题
这是我的密码:
r = requests.get('https://api.opensea.io/api/v1/assets?collection=bit birds&order_direction=asc&offset=' + (str(x)) + '&limit=1')
jsonResponse = r.json()
name = jsonResponse['assets'][0]['name']
description = jsonResponse['assets'][0]['description']
print('Name: ' + name)
print('Description: ' + str(description))
我得到了这个错误:
Traceback (most recent call last): File
"d:\generate-bitbirds-main\generate-bitbirds-main\bird_data\bitbird_generation_script_w_csv4.py",
line 1855, in <module>
name = jsonResponse['assets'][0]['name'] IndexError: list index out of range
使用API时,最好先检查请求是否成功,然后再访问响应。您可以先调用r.raise_for_status()并处理错误场景。然后在访问列表之前,首先检查它是否为空
相关问题 更多 >
编程相关推荐