问题可能是由于端口号或JSON对象数据格式不正确导致的。可以尝试以下
以下是一个代码示例,说明如何从本地主机的API获取JSON字符串:
import requests
response = requests.get('http://localhost:5000/api/user')
if response.status_code == 200:
user_data = response.json()
else:
print('Error connecting to API')