Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 download from python
#1
I'd like to download a file present at follow link

But the follow code python get me the error "HTTPError: Unauthorized":

import urllib.request
url = 'https://query1.finance.yahoo.com/v7/finance/download/TEN.MI?period1=1451602800&period2=1569708000&interval=1d&events=history&crumb=NZczOoN5ibT'
urllib.request.urlretrieve(url, 'C:/dati/xxx.csv')
Quote
#2
There's something wrong with your url.
If you try to run directly from browser, you get following:
Output:
finance error code "Unauthorized" description "Invalid cookie"
Quote
#3
(Oct-01-2019, 07:32 PM)Larz60+ Wrote: There's something wrong with your url.
If you try to run directly from browser, you get following:
Output:
finance error code "Unauthorized" description "Invalid cookie"

This is the error that I obtain from code, but from browser Chrome I obtain the downoload of a csv file.
Quote
#4
Sounds like you're missing an authorization step then,and your browser has already been authorized.
You probably need to login to use that api.
Quote
#5
(Oct-02-2019, 07:54 AM)stranac Wrote: Sounds like you're missing an authorization step then,and your browser has already been authorized.
You probably need to login to use that api.

How Can I do to obtain what you say directly from code python?
I'm interested in automatically getting the file from the web

I set it as Chrome's default browser, but the script continues to give error "HTTPError: Unauthorized"
Quote
#6
You write code that will log you in and then keep using a logged-in session.
You'll need to figure out what requests your browser makes to log you in and recreate those in your code.
Quote
#7
(Oct-03-2019, 10:34 AM)stranac Wrote: You write code that will log you in and then keep using a logged-in session.
You'll need to figure out what requests your browser makes to log you in and recreate those in your code.
quite right!
This code works:
import webbrowser
import urllib.request
url = 'https://query1.finance.yahoo.com/v7/finance/download/TEN.MI?period1=1451602800&period2=1569708000&interval=1d&events=history&crumb=NZczOoN5ibT'
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
webbrowser.get(chrome_path).open(url)
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)