It's been a while since I've worked with the Google Drive API. And I want to replace files using Google Drive API. I want to do that only using the Python HTTP requests module. Unfortunately, I always encounter an error. Could you please respond to this? It would be greatly appreciated.
CODE:
filedirectory = './Test.txt'
filename = 'Test.txt'
folderid = 'XXXXX'
updateFileId = 'XXXX'
headers = {
"Authorization": "Bearer " + str(Acesstoken),
}
metadataF= {
'id':updateFileId,
'fileId': updateFileId,
'name': filename,
'parents':[folderid]
}
files = {
'data':('metadata', json.dumps(metadataF), 'application/json; charset=UTF-8'),
'file': open("./Test.txt", "rb"),
}
r2= requests.post(
"https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart",
headers= headers,
files= files,
)
Error:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "fileIdInUse",
"message": "A file already exists with the provided ID."
}
],
"code": 409,
"message": "A file already exists with the provided ID."
}
}
<Response [409]>
It would be extremely helpful if you could assist me with this issue.