read csv file directly from URL / How to Fix a 403 Forbidden Error Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) 2019 Moderator Election Q&A - Questionnaire 2019 Community Moderator Election ResultsHow can I read in a .csv file with special characters in it in pandas?Pandas: how to read certain file type in pandasFixing misaligned rows using Pythonhow to use (read) google pre-trained word2vec model file?How to store strings in CSV with new line characters?How to read html tables under multiple headers and combine them in a single pandas dataframe?Time array ( 10 min ) for start time to next time in time series import from csv file using pythonHow to run Orange from the source code?The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all() using panda pythonInstalled module pysubgroup not found in Jupyter Notebook

Compiling and throwing simple dynamic exceptions at runtime for JVM

Raising a bilingual kid. When should we introduce the majority language?

Who can become a wight?

Assertions In A Mock Callout Test

Recursive calls to a function - why is the address of the parameter passed to it lowering with each call?

How to mute a string and play another at the same time

Can the van der Waals coefficients be negative in the van der Waals equation for real gases?

What helicopter has the most rotor blades?

Providing direct feedback to a product salesperson

How to leave only the following strings?

Why does my GNOME settings mention "Moto C Plus"?

Proving inequality for positive definite matrix

How to produce a PS1 prompt in bash or ksh93 similar to tcsh

Why do people think Winterfell crypts is the safest place for women, children & old people?

Will I be more secure with my own router behind my ISP's router?

Can a Wizard take the Magic Initiate feat and select spells from the Wizard list?

Is it OK if I do not take the receipt in Germany?

Is my guitar’s action too high?

Why are two-digit numbers in Jonathan Swift's "Gulliver's Travels" (1726) written in "German style"?

When does Bran Stark remember Jamie pushing him?

2 sample t test for sample sizes - 30,000 and 150,000

"Destructive force" carried by a B-52?

Why did Israel vote against lifting the American embargo on Cuba?

“Since the train was delayed for more than an hour, passengers were given a full refund.” – Why is there no article before “passengers”?



read csv file directly from URL / How to Fix a 403 Forbidden Error



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
2019 Moderator Election Q&A - Questionnaire
2019 Community Moderator Election ResultsHow can I read in a .csv file with special characters in it in pandas?Pandas: how to read certain file type in pandasFixing misaligned rows using Pythonhow to use (read) google pre-trained word2vec model file?How to store strings in CSV with new line characters?How to read html tables under multiple headers and combine them in a single pandas dataframe?Time array ( 10 min ) for start time to next time in time series import from csv file using pythonHow to run Orange from the source code?The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all() using panda pythonInstalled module pysubgroup not found in Jupyter Notebook










0












$begingroup$


The csv file is downloadable. I can download the file and use read_csv, But I want to read the file via direct URL in jupyter, I used the following code, but I get the HTTP 403 Forbidden
error



from io import StringIO

import pandas as pd
import requests
url="https://fineli.fi/fineli/en/elintarvikkeet/resultset.csv"
s=requests.get(url).text

c=pd.read_csv(StringIO(s))
c


how do I read the csv file via URL directly in python with a delimeter ";"










share|improve this question











$endgroup$
















    0












    $begingroup$


    The csv file is downloadable. I can download the file and use read_csv, But I want to read the file via direct URL in jupyter, I used the following code, but I get the HTTP 403 Forbidden
    error



    from io import StringIO

    import pandas as pd
    import requests
    url="https://fineli.fi/fineli/en/elintarvikkeet/resultset.csv"
    s=requests.get(url).text

    c=pd.read_csv(StringIO(s))
    c


    how do I read the csv file via URL directly in python with a delimeter ";"










    share|improve this question











    $endgroup$














      0












      0








      0





      $begingroup$


      The csv file is downloadable. I can download the file and use read_csv, But I want to read the file via direct URL in jupyter, I used the following code, but I get the HTTP 403 Forbidden
      error



      from io import StringIO

      import pandas as pd
      import requests
      url="https://fineli.fi/fineli/en/elintarvikkeet/resultset.csv"
      s=requests.get(url).text

      c=pd.read_csv(StringIO(s))
      c


      how do I read the csv file via URL directly in python with a delimeter ";"










      share|improve this question











      $endgroup$




      The csv file is downloadable. I can download the file and use read_csv, But I want to read the file via direct URL in jupyter, I used the following code, but I get the HTTP 403 Forbidden
      error



      from io import StringIO

      import pandas as pd
      import requests
      url="https://fineli.fi/fineli/en/elintarvikkeet/resultset.csv"
      s=requests.get(url).text

      c=pd.read_csv(StringIO(s))
      c


      how do I read the csv file via URL directly in python with a delimeter ";"







      python






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 38 mins ago







      KHAN irfan

















      asked 51 mins ago









      KHAN irfanKHAN irfan

      12110




      12110




















          2 Answers
          2






          active

          oldest

          votes


















          1












          $begingroup$

          The problem is that the url you have doesn't accept "non-browser" requests. The default header of Python requests is



          'User-Agent': 'python-requests/2.13.0'


          You can pass your own headers as an argument like that



          from io import StringIO
          import pandas as pd
          import requests

          headers = 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36'

          url="https://fineli.fi/fineli/en/elintarvikkeet/resultset.csv"
          s=requests.get(url, headers= headers).text

          c=pd.read_csv(StringIO(s), sep=";")
          c





          share|improve this answer











          $endgroup$












          • $begingroup$
            SyntaxError: illegal target for annotation
            $endgroup$
            – KHAN irfan
            23 mins ago










          • $begingroup$
            can you try now? I am running it on codelab right now and I don't get any error.
            $endgroup$
            – Tasos
            18 mins ago


















          0












          $begingroup$

          I read the file using the following code



          from urllib.request import urlopen, Request
          headers = "User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.3"
          reg_url = "https://fineli.fi/fineli/en/elintarvikkeet/resultset.csv"
          req = Request(url=reg_url, headers=headers)
          html = urlopen(req).read()
          print(html)





          share|improve this answer









          $endgroup$













            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "557"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f49751%2fread-csv-file-directly-from-url-how-to-fix-a-403-forbidden-error%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1












            $begingroup$

            The problem is that the url you have doesn't accept "non-browser" requests. The default header of Python requests is



            'User-Agent': 'python-requests/2.13.0'


            You can pass your own headers as an argument like that



            from io import StringIO
            import pandas as pd
            import requests

            headers = 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36'

            url="https://fineli.fi/fineli/en/elintarvikkeet/resultset.csv"
            s=requests.get(url, headers= headers).text

            c=pd.read_csv(StringIO(s), sep=";")
            c





            share|improve this answer











            $endgroup$












            • $begingroup$
              SyntaxError: illegal target for annotation
              $endgroup$
              – KHAN irfan
              23 mins ago










            • $begingroup$
              can you try now? I am running it on codelab right now and I don't get any error.
              $endgroup$
              – Tasos
              18 mins ago















            1












            $begingroup$

            The problem is that the url you have doesn't accept "non-browser" requests. The default header of Python requests is



            'User-Agent': 'python-requests/2.13.0'


            You can pass your own headers as an argument like that



            from io import StringIO
            import pandas as pd
            import requests

            headers = 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36'

            url="https://fineli.fi/fineli/en/elintarvikkeet/resultset.csv"
            s=requests.get(url, headers= headers).text

            c=pd.read_csv(StringIO(s), sep=";")
            c





            share|improve this answer











            $endgroup$












            • $begingroup$
              SyntaxError: illegal target for annotation
              $endgroup$
              – KHAN irfan
              23 mins ago










            • $begingroup$
              can you try now? I am running it on codelab right now and I don't get any error.
              $endgroup$
              – Tasos
              18 mins ago













            1












            1








            1





            $begingroup$

            The problem is that the url you have doesn't accept "non-browser" requests. The default header of Python requests is



            'User-Agent': 'python-requests/2.13.0'


            You can pass your own headers as an argument like that



            from io import StringIO
            import pandas as pd
            import requests

            headers = 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36'

            url="https://fineli.fi/fineli/en/elintarvikkeet/resultset.csv"
            s=requests.get(url, headers= headers).text

            c=pd.read_csv(StringIO(s), sep=";")
            c





            share|improve this answer











            $endgroup$



            The problem is that the url you have doesn't accept "non-browser" requests. The default header of Python requests is



            'User-Agent': 'python-requests/2.13.0'


            You can pass your own headers as an argument like that



            from io import StringIO
            import pandas as pd
            import requests

            headers = 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36'

            url="https://fineli.fi/fineli/en/elintarvikkeet/resultset.csv"
            s=requests.get(url, headers= headers).text

            c=pd.read_csv(StringIO(s), sep=";")
            c






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 19 mins ago

























            answered 26 mins ago









            TasosTasos

            1,62011138




            1,62011138











            • $begingroup$
              SyntaxError: illegal target for annotation
              $endgroup$
              – KHAN irfan
              23 mins ago










            • $begingroup$
              can you try now? I am running it on codelab right now and I don't get any error.
              $endgroup$
              – Tasos
              18 mins ago
















            • $begingroup$
              SyntaxError: illegal target for annotation
              $endgroup$
              – KHAN irfan
              23 mins ago










            • $begingroup$
              can you try now? I am running it on codelab right now and I don't get any error.
              $endgroup$
              – Tasos
              18 mins ago















            $begingroup$
            SyntaxError: illegal target for annotation
            $endgroup$
            – KHAN irfan
            23 mins ago




            $begingroup$
            SyntaxError: illegal target for annotation
            $endgroup$
            – KHAN irfan
            23 mins ago












            $begingroup$
            can you try now? I am running it on codelab right now and I don't get any error.
            $endgroup$
            – Tasos
            18 mins ago




            $begingroup$
            can you try now? I am running it on codelab right now and I don't get any error.
            $endgroup$
            – Tasos
            18 mins ago











            0












            $begingroup$

            I read the file using the following code



            from urllib.request import urlopen, Request
            headers = "User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.3"
            reg_url = "https://fineli.fi/fineli/en/elintarvikkeet/resultset.csv"
            req = Request(url=reg_url, headers=headers)
            html = urlopen(req).read()
            print(html)





            share|improve this answer









            $endgroup$

















              0












              $begingroup$

              I read the file using the following code



              from urllib.request import urlopen, Request
              headers = "User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.3"
              reg_url = "https://fineli.fi/fineli/en/elintarvikkeet/resultset.csv"
              req = Request(url=reg_url, headers=headers)
              html = urlopen(req).read()
              print(html)





              share|improve this answer









              $endgroup$















                0












                0








                0





                $begingroup$

                I read the file using the following code



                from urllib.request import urlopen, Request
                headers = "User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.3"
                reg_url = "https://fineli.fi/fineli/en/elintarvikkeet/resultset.csv"
                req = Request(url=reg_url, headers=headers)
                html = urlopen(req).read()
                print(html)





                share|improve this answer









                $endgroup$



                I read the file using the following code



                from urllib.request import urlopen, Request
                headers = "User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.3"
                reg_url = "https://fineli.fi/fineli/en/elintarvikkeet/resultset.csv"
                req = Request(url=reg_url, headers=headers)
                html = urlopen(req).read()
                print(html)






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 27 mins ago









                KHAN irfanKHAN irfan

                12110




                12110



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Data Science Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    Use MathJax to format equations. MathJax reference.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f49751%2fread-csv-file-directly-from-url-how-to-fix-a-403-forbidden-error%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Францішак Багушэвіч Змест Сям'я | Біяграфія | Творчасць | Мова Багушэвіча | Ацэнкі дзейнасці | Цікавыя факты | Спадчына | Выбраная бібліяграфія | Ушанаванне памяці | У філатэліі | Зноскі | Літаратура | Спасылкі | НавігацыяЛяхоўскі У. Рупіўся дзеля Бога і людзей: Жыццёвы шлях Лявона Вітан-Дубейкаўскага // Вольскі і Памідораў з песняй пра немца Адвакат, паэт, народны заступнік Ашмянскі веснікВ Минске появится площадь Богушевича и улица Сырокомли, Белорусская деловая газета, 19 июля 2001 г.Айцец беларускай нацыянальнай ідэі паўстаў у бронзе Сяргей Аляксандравіч Адашкевіч (1918, Мінск). 80-я гады. Бюст «Францішак Багушэвіч».Яўген Мікалаевіч Ціхановіч. «Партрэт Францішка Багушэвіча»Мікола Мікалаевіч Купава. «Партрэт зачынальніка новай беларускай літаратуры Францішка Багушэвіча»Уладзімір Іванавіч Мелехаў. На помніку «Змагарам за родную мову» Барэльеф «Францішак Багушэвіч»Памяць пра Багушэвіча на Віленшчыне Страчаная сталіца. Беларускія шыльды на вуліцах Вільні«Krynica». Ideologia i przywódcy białoruskiego katolicyzmuФранцішак БагушэвічТворы на knihi.comТворы Францішка Багушэвіча на bellib.byСодаль Уладзімір. Францішак Багушэвіч на Лідчыне;Луцкевіч Антон. Жыцьцё і творчасьць Фр. Багушэвіча ў успамінах ягоных сучасьнікаў // Запісы Беларускага Навуковага таварыства. Вільня, 1938. Сшытак 1. С. 16-34.Большая российская1188761710000 0000 5537 633Xn9209310021619551927869394п

                    Partai Komunis Tiongkok Daftar isi Kepemimpinan | Pranala luar | Referensi | Menu navigasidiperiksa1 perubahan tertundacpc.people.com.cnSitus resmiSurat kabar resmi"Why the Communist Party is alive, well and flourishing in China"0307-1235"Full text of Constitution of Communist Party of China"smengembangkannyas

                    ValueError: Expected n_neighbors <= n_samples, but n_samples = 1, n_neighbors = 6 (SMOTE) The 2019 Stack Overflow Developer Survey Results Are InCan SMOTE be applied over sequence of words (sentences)?ValueError when doing validation with random forestsSMOTE and multi class oversamplingLogic behind SMOTE-NC?ValueError: Error when checking target: expected dense_1 to have shape (7,) but got array with shape (1,)SmoteBoost: Should SMOTE be ran individually for each iteration/tree in the boosting?solving multi-class imbalance classification using smote and OSSUsing SMOTE for Synthetic Data generation to improve performance on unbalanced dataproblem of entry format for a simple model in KerasSVM SMOTE fit_resample() function runs forever with no result