1

I have been trying for several hours to access a CSV file on my Google drive.

I was able to access the drive. I actually created the file myself with another script. Now what I need is to import that file in Pandas with read_csv.

pd.read_csv('https://drive.google.com/uc?id=1k5Q9wuq-mIeCl1zpPF0DJ31uzlJ8QfSO',encoding="ISO-8859-1")

When I try to do it, I get the following error:

ParserError: Error tokenizing data. C error: Expected 1 fields in line 6, saw 2

I have realized that it has something to do with the share permissions. The error appears if the file is available in a restricted way. But if I manually change that to 'anyone with the link', then it works and pandas can create the df.

I also tried

read_csv('https://drive.google.com/uc?id=1k5Q9wuq-mIeCl1zpPF0DJ31uzlJ8QfSO',encoding="ISO-8859-1",error_bad_lines=False)

However, it gives a summary of fields as a 1 column table, but it help me to confirm that the problem isn't on the google drive connection.

What can I do to fix this or how can I change those file permissions temporarily to read the DF and then restore the permissions to 'restricted'.

Thanks.

p929
  • 73
  • 1
  • 1
  • 4
  • If you don't share permissions, pandas won't download the .csv file, but an html page with a permissions error, which will not parse correctly as .csv. If I follow the link from your question, I get a Google login page, not a csv file. – w-m Oct 06 '21 at 17:42
  • My dilemma is that the file is in a folder on my own drive. Therefore, my assumption is that it must be somehow accessible through python (in the end it was myself who uploaded it there with the google drive api). Unfortunately, I can't allow the files I'm planning to use this code on to be public. It would also be OK if I could allow the file to be public (set to 'anyone with the link') just before being read in pandas and set back to restricted after being uploaded to the DF, but I honestly don't know if that's even possible – p929 Oct 06 '21 at 19:52
  • It's not public if you don't give out the link to anyone. – w-m Oct 06 '21 at 19:54
  • ok, fair enough. then I think the problem reduces to how to change file permissions from python. I guess there is a property I have to give to the file when I created it via pydrive2, any idea? – p929 Oct 07 '21 at 05:22
  • https://stackoverflow.com/q/51411985/463796 ? – w-m Oct 07 '21 at 10:04

0 Answers0