I am using Google Indexing API, and I am getting this error
argument should be integer or bytes-like object, not 'str'
I am implementing the API on the Django server when I run it on my local machine it runs just fine. but when I put it on pythonanywhere it is giving me the above error. I don't know what's the reason for this error. here is the function
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)
In the other cases that exception was raised by PySocks
and upgrade PySocks
solved it. Assuming that you run it outside the virtual environment with python3.8
upgrade PySocs with pip3.8 install --user --force-reinstall PySocks
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.