Feb-19-2020, 03:05 AM
(This post was last modified: Feb-19-2020, 03:06 AM by andrewnzinuk.)
Hi
Here is my code - I am getting a 500 error and do not understand why. The basic premise is to mirror what I can do in the browser. I can download the data using the download button on the first URL (bottom right). Selecting data a new window is created and I copy the URL generated in the new window into my existing browser session (new window) and it works. I am now trying to replicate via Python. Quite a simple script - but clearly I am missing something obvious.
****************************************************
import requests
import urllib.request
import time
from bs4 import BeautifulSoup
import json
print("Running")
url = 'https://public.tableau.com/views/EVv3/Story1?:embed=yes&:showVizHome=no&:tabs=no&:toolbar=no/mot-resources/vehicle-fleet-statistics/monthly-electric-and-hybrid-light-vehicle-registrations/nz-light-ev-registration-by-brand-may-2013-june-2019'
session = requests.Session()
r = session.get(url)
print ("Original Session is : " + str(session))
session_id = (r.headers['X-Session-Id'])
print("Session ID is : " + str(session_id))
url2 = 'https://public.tableau.com/vizql/w/EVv3/v/Story1/vud/sessions/' + session_id + '/views/13720889704328586040_2190967132146547508?csv=true'
print(url2)
filename2 = "C:\\temp\\metro\\elec.csv"
#urllib.request.urlretrieve(url2,filename2)
r = session.get(url2)
print ("New Session is : " + str(session))
print®
***************************************************
Any thoughts much appreciated.
Regards
Andrew
Here is my code - I am getting a 500 error and do not understand why. The basic premise is to mirror what I can do in the browser. I can download the data using the download button on the first URL (bottom right). Selecting data a new window is created and I copy the URL generated in the new window into my existing browser session (new window) and it works. I am now trying to replicate via Python. Quite a simple script - but clearly I am missing something obvious.
****************************************************
import requests
import urllib.request
import time
from bs4 import BeautifulSoup
import json
print("Running")
url = 'https://public.tableau.com/views/EVv3/Story1?:embed=yes&:showVizHome=no&:tabs=no&:toolbar=no/mot-resources/vehicle-fleet-statistics/monthly-electric-and-hybrid-light-vehicle-registrations/nz-light-ev-registration-by-brand-may-2013-june-2019'
session = requests.Session()
r = session.get(url)
print ("Original Session is : " + str(session))
session_id = (r.headers['X-Session-Id'])
print("Session ID is : " + str(session_id))
url2 = 'https://public.tableau.com/vizql/w/EVv3/v/Story1/vud/sessions/' + session_id + '/views/13720889704328586040_2190967132146547508?csv=true'
print(url2)
filename2 = "C:\\temp\\metro\\elec.csv"
#urllib.request.urlretrieve(url2,filename2)
r = session.get(url2)
print ("New Session is : " + str(session))
print®
***************************************************
Any thoughts much appreciated.
Regards
Andrew