1

I Uploaded a python script into my Google Drive, and download it into Google Colab by:

!wget "https://drive.google.com/[URL]" -O "script.py"

After downloading, when I import function from script in a cell in Google Colab:

from script.py import my_fun

I get the error:

File "/content/script.py", line 2
    <!DOCTYPE html>
    ^
SyntaxError: invalid syntax

When I check the content of "script.py", it is similar to a HTML file not python script. Is there anyway to download python script to Google Colab?

Is there any chance that the Google Drive URL that I use is wrong?

How I get URL in Google Drive:

  • Right click on the script file in Google Drive
  • Select "Get Link"
  • I select my company group and select "viewer" permission.
  • Click "Copy Link"

Thank you for reading my question.

Mohammad
  • 775
  • 1
  • 14
  • 37
  • That's not an error, it's just a feature of how Google Drive serves content. Probably find a less crazy way to host your scripts; GitHub allows you to serve up things raw, without HTML headers. – tripleee Apr 26 '21 at 07:24

1 Answers1

1

I think the problem might be related to the use itself of wget. https://stackoverflow.com/a/39087286/12664376 This answer to the question download-a-file-from-google-drive-using-wget might help you. Note that some people say it doesn't work anymore, so see some acomments on that answer, or this other answer https://stackoverflow.com/a/58821707/12664376.

selenio34
  • 92
  • 1
  • 9