8

I have a python script that loads a csv file from a server via https. I'm behind a corporate proxy, so I need to provide that info to the script.

Let

proxy_dict = {"https://user:password@10.10.1.1:8080"}

where all values are changed to be correct.

Using

print(requests.get(my_url, proxies=proxy_dict).text[:1000]

works as expected.

I want to use pandas.read_csv, which does not have a proxy argument.

How do I set the proxy for pandas? Either as a variable, or for the kernel, or system-wide, as long as only Python is affected.

Running Anaconda 3.6.3 x64 on Windows 7 x64.

Thank you!

zuiqo
  • 1,149
  • 1
  • 10
  • 23

2 Answers2

8

Maybe you can read the csv from a string, by using io.StringIO.

Please see the answer on: Pandas read_csv from url

import io

s = requests.get(my_url, proxies=proxy_dict).text

df = pd.read_csv(io.StringIO(s))
PythonSherpa
  • 2,560
  • 3
  • 19
  • 40
1

In addition, you need to do: proxy_dict = dict("https://user:password@10.10.1.1:8080")

William Prigol Lopes
  • 1,803
  • 14
  • 31
elf
  • 11
  • 1
  • "ValueError: dictionary update sequence element #0 has length 1; 2 is required" this might work: proxy_dict = {"anything" : "https://user:password@10.10.1.1:8080"} – DrWhat Jun 18 '21 at 07:59
  • Yes, proxy_dict needs to be a dict. I use the keys 'http' and 'https' in the proxy dict with the proxy you want to use). This should work for you. – Charles Plager Jan 13 '23 at 21:07