Home > OS >  csv file not workinf properly
csv file not workinf properly

Time:07-12

so I created a simple code to read a csv file in python 3.0 using pandas

import pandas as pd

df = pd.read_csv('https://www.goodreads.com/review_porter/export/153331182/goodreads_export.csv', on_bad_lines= 'skip')

print(df)
and instead of the csv file i ended with this:
<!DOCTYPE html>
0                                               <html>
1                                               <head>
2                               <title>Sign Up</title>
3    <meta content='telephone=no' name='format-dete...
4    <link href='https://www.goodreads.com/user/sig...
..                                                 ...
255                                                  }
256                                              //]]>
257                                          </script>
258                                            </html>
259  <!-- This is a random-length HTML comment: xme...

[260 rows x 1 columns]

can someone help me understand why in this particular case is not working, becouse i tryed another .csv and worked just fine. The site that i use is https://www.goodreads.com/ and the .csv file is from the export section.

CodePudding user response:

Thats because that link need you to be authenticated before you can access the csv file. Since you have not passed any authentication it just read the sign up page and displaying the HTML format.

You can try this:

import requests
response = requests.get(url, auth=(username, password), verify=False)

Even if you download the csv file, it should work too.

CodePudding user response:

You need authentication to access this url so it fails.

Check this link :

Pandas read_csv from url

  • Related