所以我试图通过使用GMAIL API获得消息。这样做需要我提供一个messageID。我在本地列表中存储了几个消息id。但是,当我尝试将list-元素作为迭代传递给GET请求时,它将简单地使用变量值作为字符串,而不是变量本身。有什么办法可以规避吗?即,将id='str(s)替换为变量
中的实际数字'12345234534'。for s in ID_List:
req_result = service.users().messages().get(userId='me', id='str(s)').execute()
返回以下错误:
File "redacted", line 60, in main
req_result = service.users().messages().get(userId='me', id='str(s)').execute()
File "redactedPython39libsite-packagesgoogleapiclient_helpers.py", line 134, in positional_wrapper
return wrapped(*args, **kwargs)
File "redactedPythonPython39libsite-packagesgoogleapiclienthttp.py", line 915, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://gmail.googleapis.com/gmail/v1/users/me/messages/str%28s%29?alt=json returned "Invalid id value". Details: "Invalid id value">
是否有可能,Gmail API不会让我传递变量作为查询字符串?
提前感谢!
试试这个:
req_result = service.users().messages().get(userId='me', id=s).execute()