The purpose of this script is to connect to an API endpoint that provides a .CSV file. I'm not trying to manipulate the data or do anything with the information other than grab it from the endpoint and then save the file to a local directory
I've tested the endpoint and can get a 200 HTTP response from it, but I can not open the file or save it. I continue to get a typeerror response for the last line of the code.
import urllib.request as urllib2
import requests
from requests.auth import HTTPBasicAuth
import csv
url = "Https://API_LINK/Details/full_csv"
request = urllib2.Request(url)
request.add_header('header_details', 'Token token="token_details"')
response = urllib2.urlopen(request)
with open(response,'w', newline='') as f:
I expected to be able to define the opened file as 'f', then pass 'f' to csv.reader() and then view rows from the file. What do I do to pass the info as bytes and not as just an httpResponse?
requestsbut only usingurllib2? - clubby789requestsis better thanurllib2, so you might consider using that instead. - clubby789