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
$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 ";"
python
$endgroup$
add a comment |
$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 ";"
python
$endgroup$
add a comment |
$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 ";"
python
$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
python
edited 38 mins ago
KHAN irfan
asked 51 mins ago
KHAN irfanKHAN irfan
12110
12110
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
$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
$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
add a comment |
$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)
$endgroup$
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
$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
$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
add a comment |
$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
$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
add a comment |
$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
$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
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
add a comment |
$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
add a comment |
$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)
$endgroup$
add a comment |
$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)
$endgroup$
add a comment |
$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)
$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)
answered 27 mins ago
KHAN irfanKHAN irfan
12110
12110
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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