Python httplib2:-参数应该是整数或类似对象的字节,而不是';str';
我正在使用谷歌索引API,我得到了这个错误 参数应为整数或类似字节的对象,而不是“str” 我在Django服务器上实现API,当我在本地机器上运行它时,它运行得很好。 但是当我把它放在pythonany上,它给了我上面的错误。我不知道这个错误的原因是什么。 下面是函数Python httplib2:-参数应该是整数或类似对象的字节,而不是';str';,python,django,linux,httplib2,Python,Django,Linux,Httplib2,我正在使用谷歌索引API,我得到了这个错误 参数应为整数或类似字节的对象,而不是“str” 我在Django服务器上实现API,当我在本地机器上运行它时,它运行得很好。 但是当我把它放在pythonany上,它给了我上面的错误。我不知道这个错误的原因是什么。 下面是函数 def demo(request): context = {} if request.GET: link = request.GET.get('link') key = reque
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)
在这个例子中,异常是由
PySocks
引发的,升级PySocks
解决了这个问题。假设您使用python3.8
在虚拟环境之外运行它,并使用pip3.8安装--user--force重新安装PySocks
升级PySocks,则异常是由PySocks
引发的,升级PySocks
解决了它。假设您使用python3.8
在虚拟环境之外运行它,则使用pip3.8安装--user--force重新安装PySocks升级PySocs
谢谢,它成功了谢谢