4

I need to override an existing file inside a google drive folder with a new file. This is what I have.

file = drive.CreateFile({'id': <id_of_file_which_I_wish_to_overwrite>})
file.SetContentFile(<my_file_path>)
file.Upload()
print('title: %s, mimeType: %s' % (file5['title'], file5['mimeType']))

I keep getting an error from file.Upload() line such as this:

RedirectMissingLocation: Redirected but the response is missing a Location: header.

Any ideas of what's causing this? What this Location is or the header? I noticed that I am not getting this error when I run the same code without file.SetContentFile and instead only change file metadata instead of overwriting it.

user10467920
  • 41
  • 1
  • 2
  • Hello @user10467920, which libraries are you using for your project? Cheers! – ale13 Mar 05 '20 at 15:43
  • Hi @ale13 , I'm using the following: from pydrive.auth import GoogleAuth and from pydrive.drive import GoogleDrive My authentication seems to work fine because I've used the setup before on other projects. It's only when I run the f.Upload() method that I get the error. – user10467920 Mar 05 '20 at 18:20
  • So it seems like the problem was the size of the file I was trying to upload on google drive. Running the exact same thing as the code I gave above worked for a much much smaller subset of that same data on the file. My original file was huge (a few million records) so it was throwing the RedirectMissingLocation error. I find that the error message wasn't really informative/descriptive of what was actually happening. In any case, my problem is solve now. – user10467920 Mar 05 '20 at 22:37

2 Answers2

15

You know, PyDrive is a wrapper library of google-api-python-client.

According to this issue, there is some problem between google-api-python-client and httplib2.

So try installing a 0.15.0 version of httplib2. pip install httplib2==0.15.0

blurfx
  • 1,270
  • 11
  • 22
4

You should take a look at the size of the file that is being uploaded on Google Drive since you are getting the RedirectMissingLocation error.

Running the code above works for a much much smaller subset of that same data on the file.

ale13
  • 5,679
  • 3
  • 10
  • 25