![]() |
string.format() suddenly causing errors with google drive API - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: string.format() suddenly causing errors with google drive API (/thread-34123.html) |
string.format() suddenly causing errors with google drive API - zwitrader - Jun-28-2021 This morning I abruptly started having problems with previously working (unchanged) code to access google drive via their API. Briefly, the following code was working this morning (and for the past several days), but suddenly stopped working today: myFolderID = 'kjl234987fh435kjwef920fsdlksA6GD' myFileList = service.files().list(q=" '{0}' in parents and trashed=false".format(myFolderID) , fields='files(id, name)'.execute()Conversely, if I include the string directly in the query, I get no error and am still able to run the code: myFileList = service.files().list(q=" 'kjl234987fh435kjwef920fsdlksA6GD' in parents and trashed=false".format(myFolderID) , fields='files(id, name)'.execute()So, the problem seems to be related to the way string.format() is interacting with the query. I confirmed that the variable myFolderIDwas storing the correct value by issuing various print() commands: print("{0}".format(myFolderID)) print(f"{myFolderID}") print("%s" % (myFolderID))all of which printed the correct string (kjl234987fh435kjwef920fsdlksA6GD). However, all of these string formatting variations resulted in the same error when used in the query. I am running Python 3.9 on macOS Catalina. Here is the Traceback error displayed in Terminal:
|