【发布时间】:2021-01-26 10:38:34
【问题描述】:
我正在使用 Google Indexing API,但出现此错误
参数应该是整数或类似字节的对象,而不是'str'
当我在本地机器上运行它时,我正在 Django 服务器上实现 API,它运行得很好。 但是当我把它放在 pythonanywhere 上时,它给了我上述错误。我不知道这个错误的原因是什么。 这是函数
def demo(request):
context = {}
if request.GET:
link = request.GET.get('link')
key = request.GET.get('key')
if link and key:
context = {
'link': link,
'key': key,
}
try:
key = json.loads(key)
except:
return render(request, 'google_api_demo/index.html', context)
scope = [ "https://www.googleapis.com/auth/indexing" ]
endpoint = "https://indexing.googleapis.com/v3/urlNotifications:publish"
credentials = ServiceAccountCredentials.from_json_keyfile_dict(key, scopes=scope)
http = credentials.authorize(httplib2.Http())
content = bytes(str({
"url": f"{link}",
"type": "URL_UPDATED",
}), encoding='utf-8')
response, content = http.request(endpoint, method="POST", body=content)
context['response'] = response
context['content'] = content
return render(request, 'google_api_demo/index.html', context)
return render(request, 'google_api_demo/index.html', context)
【问题讨论】:
标签: python django linux httplib2