alextc
alextc

Reputation: 3515

Proxy settings for urllib.urlretrieve

I am using urllib.urlretrieve to download a file on a remote FTP site with the anonymous pattern.

ftp://ftp.{DOMAIN}/register/{FOLDER1}/{FOLDER2}/{FOLDER3}/{FILE}

import urllib
urllib.urlretrieve(FILE_TO_DOWNLOAD, DESTINATION_FILE)

When it was run on my company computer, it gave me an error as below:

IOError: [Errno ftp error] proxy support for ftp protocol currently not implemented

I know it lacks of proxy settings in the code, but I have no idea where and how to set up my proxy settings.

Upvotes: 2

Views: 3582

Answers (1)

Avantol13
Avantol13

Reputation: 1059

How to set up proxies:

Python 2.7.10

Pass into urlopen with proxy. See documentation here:

# Use http://www.someproxy.com:3128 for http proxying
proxies = {'http': 'http://www.someproxy.com:3128'}
filehandle = urllib.urlopen(some_url, proxies=proxies)

Or, set the http_proxy environmental variable before starting the python interpreter.

% http_proxy="http://www.someproxy.com:3128"
% export http_proxy
% python

Python 3.5

This is right from the documentation here.

import urllib.request
proxies = {'http': 'http://proxy.example.com:8080/'}
opener = urllib.request.FancyURLopener(proxies)
with opener.open("http://www.python.org") as f:
f.read().decode('utf-8')

Upvotes: 2

Related Questions