1

I have a Python program to access different links and download files. I'm using Python "Requests".

What I want is to authenticate on to a site only once and then use a loop to download from its different sublinks.

Current code which works is as below :

for k,v in OS.items():
  response = requests.get(v, auth=HTTPBasicAuth('xxxx@yyy.com', 'xxxxx'), allow_redirects=True, verify=False)
  con = response.content[3856:]
  open(f"{k}.csv", 'wb').write(con)
  response.close()

I have a dict where different "filenames" as keys are mapped to their respective download link "url's" as values. The code works fine, but I know the above code is not right as in each loop it has to keep authenticating and downloading. Can someone suggest a better solution.

  • Does this answer your question? [Python Requests and persistent sessions](https://stackoverflow.com/questions/12737740/python-requests-and-persistent-sessions) – sqz Jul 22 '20 at 17:02

0 Answers0