Python Forum
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')
Reply
#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"
Reply
#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.
Reply
#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.
Reply
#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"
Reply
#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.
Reply
#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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  M4S file extensin in Streaming video. How to download and use in Python Man_from_India 0 2,846 Aug-20-2020, 07:48 AM
Last Post: Man_from_India

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020