Python Forum
string.format() suddenly causing errors with google drive API
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
string.format() suddenly causing errors with google drive API
#1
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
myFolderID
was 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:

Error:
Traceback (most recent call last): File "/Users/user/Desktop/Script_B.py", line 508, in <module> myFileList = service.files().list(q=" '{0}' in parents and trashed=false".format(myFolderID) , fields='files(id, name)'.execute() File "/Users/user/opt/anaconda3/lib/python3.8/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper return wrapped(*args, **kwargs) File "/Users/user/opt/anaconda3/lib/python3.8/site-packages/googleapiclient/http.py", line 935, in execute raise HttpError(resp, content, uri=self.uri) googleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/drive/v3/files?q=parents+%3D+%27kjl234987fh435kjwef920fsdlksA6GD%0A%27+and+trashed%3Dfalse&fields=files%28id%2C+name%29&spaces=drive&alt=json returned "File not found: .". Details: "[{'domain': 'global', 'reason': 'notFound', 'message': 'File not found: .', 'locationType': 'parameter', 'location': 'fileId'}]">
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question How to get a removable disc type in drive Daring_T 12 971 Feb-11-2024, 08:55 AM
Last Post: Gribouillis
Information subprocess.Popen() suddenly giving me grief? davecotter 3 533 Dec-13-2023, 10:49 PM
Last Post: davecotter
  open python files in other drive akbarza 1 632 Aug-24-2023, 01:23 PM
Last Post: deanhystad
  Integrating Google Drive in App Lahearle 0 441 Jul-19-2023, 05:51 PM
Last Post: Lahearle
  print(data) is suddenly invalid syntax db042190 6 1,122 Jun-14-2023, 02:55 PM
Last Post: deanhystad
  Set string in custom format korenron 4 1,048 Jan-16-2023, 07:46 PM
Last Post: mutantGOD
  code to send attachments contained on the drive. stefanoste78 1 822 Oct-12-2022, 02:16 AM
Last Post: Larz60+
  Format String NewPi 2 908 Oct-10-2022, 05:50 PM
Last Post: NewPi
  Python debug suddenly got bad ben1122 3 1,062 Sep-03-2022, 06:20 AM
Last Post: ben1122
  access is denied error 5 for network drive mapping ? ahmedbarbary 2 1,731 Aug-17-2022, 10:09 PM
Last Post: ahmedbarbary

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020