我正在尝试从我的 Python Web 应用程序调用 Personality Insights API,但它总是返回禁止错误 403,但是当我从 Postman Chrome 扩展程序调用它时,它可以成功运行。
这是我的python代码:
def generatePersonalDescription(request):
import requests
from requests.auth import HTTPBasicAuth
IBM_API_URL = "https://gateway.watsonplatform.net/personality-insights/api/v2/profile"
top_level_url = "https://gateway.watsonplatform.net/personality-insights/api"
username = "<user>"
password = "<password>"
JSON_OBJ = {'contentItems': [{'content' : 'strcontent' , 'contenttype': 'application/json','sourceid': 'blog123','language': 'en'}]}
json_data = json.dumps(JSON_OBJ)
resp = requests.get(IBM_API_URL, auth=(username, password))
return HttpResponse(resp)
是否有可能因为 python 是服务器端并且 API 不允许接受来自服务器端应用程序的请求?