mjmostachetti
mjmostachetti

Reputation: 716

HTTPS request in python 2.7

I can't find documentation on this. Is it possible to run an https request in python 2.7?

I tried this code for 3.2, but these modules don't exist in 2.7.

import urllib.request
r = urllib.request.urlopen('https://openapi.etsy.com/v2/users/redluck2013/profile?        fields=transaction_sold_count&api_key=1pmmjgt3j4nz5ollhzz2hvib')
print(r.read())

Upvotes: 2

Views: 4715

Answers (3)

chishaku
chishaku

Reputation: 4643

Regarding https, please note:

Warning HTTPS requests do not do any verification of the server’s certificate.

http://docs.python.org/2/library/urllib2.html

If you do require https verification, python requests is a very useful library

import requests
url = https://openapi.etsy.com/v2/users/redluck2013/profile?fields=transaction_sold_count&api_key=1pmmjgt3j4nz5ollhzz2hvib
r = requests.get(url, verify=True)
content = r.text

For the verification, just make sure to pass True to the verify argument.

More here:

Upvotes: 0

Ruben Bermudez
Ruben Bermudez

Reputation: 2333

With 2.7:

import urllib2

r = urllib2.urlopen('https://openapi.etsy.com/v2/users/redluck2013/profile?fields=transaction_sold_count&api_key=1pmmjgt3j4nz5ollhzz2hvib')

print(r.read())

See http://docs.python.org/2/howto/urllib2.html

Upvotes: 1

njzk2
njzk2

Reputation: 39406

Package urllib.request was added in python 3, it does not exist in python 2.7.

In python 2.7, use urllib.urlopen

This has nothing to do with https.

Upvotes: 1

Related Questions