Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
268 views
in Technique[技术] by (71.8m points)

python - TypeError: can't concat str to bytes for google indexing API

I'm trying to use Google's indexing API to push page crawl in GSC but I'm currently getting this error "TypeError: can't concat str to bytes".

CODE:

from oauth2client.service_account import ServiceAccountCredentials
import httplib2
import json
import pandas as pd

SCOPES = "https://www.googleapis.com/auth/indexing"
ENDPOINT = "https://indexing.googleapis.com/v3/urlNotifications:publish"
JSON_KEY_FILE = "river-formula-BLABLA.json"

credentials = ServiceAccountCredentials.from_json_keyfile_name(JSON_KEY_FILE, scopes=SCOPES)
http = credentials.authorize(httplib2.Http())
content = {"url":"https://www.parmalat.it/chef/ricette/cannelloni-al-ragu","type":"URL_UPDATED"}

response, content=http.request(ENDPOINT, method="POST", body=content)

print(response)
print(content)

RESULT:

~Anaconda3libhttpclient.py in _send_output(self, message_body, encode_chunked)

   1041                 if encode_chunked and self._http_vsn == 11:
   1042                     # chunked encoding
-> 1043                     chunk = f'{len(chunk):X}
'.encode('ascii') + chunk 
   1044                         + b'
'
   1045                 self.send(chunk)

TypeError: can't concat str to bytes

I deleted most of the result code because otherwise it wouldn't let me post the question. Let me know if you need more context and I will try to post the remaining part.

Maybe my python version is too updated (python 3). Any guesses?

question from:https://stackoverflow.com/questions/65881771/typeerror-cant-concat-str-to-bytes-for-google-indexing-api

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...