PythonでGoogle Indexing APIを連続実行したいが、JSONの代入?ができない

前提

PythonでGoogle Indexing APIを連続実行したいが、JSONの代入?ができない

実現したいこと

・Excelファイルを読み込む
・Excelファイルに記載されているURLを以下キャプチャの赤線部分に、自動的に埋め込んで実行させたい
イメージ説明

発生している問題・エラーメッセージ

400エラーが表示される

該当のソースコード

Python

from oauth2client.service_account import ServiceAccountCredentials import httplib2 import openpyxl wb =openpyxl.load_workbook('sample.xlsx')sheet = wb['sheet'] for i in range(2): URL = sheet.cell(row = 1+i, column = 1).value SCOPES = [ "https://www.googleapis.com/auth/indexing" ] ENDPOINT = "https://indexing.googleapis.com/v3/urlNotifications:publish" # service_account_file.json is the private key that you created for your service account. JSON_KEY_FILE = "/content/sample-indexing-api.json" credentials = ServiceAccountCredentials.from_json_keyfile_name(JSON_KEY_FILE, scopes=SCOPES) http = credentials.authorize(httplib2.Http()) # Define contents here as a JSON string. # This example shows a simple update request. # Other types of requests are described in the next step. content = """{ \"url\": \"{{URL}}\", \"type\": \"URL_UPDATED\" }""" response, content = http.request(ENDPOINT, method="POST", body=content) if response.status == 200: print(f'成功しています。 ステータス:{response.status} ') else: print(f'成功しませんでした。ステータス: {response.status} ')

"url": "{{URL}}", 部分をどう記述したらよいのか、ご教示いただけますと幸いですm(__)m

コメントを投稿

0 コメント