1

I am trying to run script in Debian.
In python2 and python3 I get error "No module named 'httplib'"

$sudo pip install httplib2

and

$sudo pip3 install httplib2

did not help.


import httplib
import urllib
import json
import hashlib
import hmac
from collections import OrderedDict

server = "api.---.net"
api_key = "---"
secret_key = "---"


def get(url):
    conn = httplib.HTTPSConnection(server)
    conn.request("GET", url)
    response = conn.getresponse()
    data = json.load(response)
    conn.close()
    return data

def post(url, params):
    conn = httplib.HTTPSConnection(server)
    data = OrderedDict(sorted(params))
    encoded_data = urllib.urlencode(data)
    sign = hmac.new(secret_key, msg=encoded_data, digestmod=hashlib.sha256).hexdigest().upper()
    headers = {"Api-key": api_key, "Sign": sign, "Content-type": "application/x-www-form-urlencoded"}
    conn.request("POST", url, encoded_data, headers)
    response = conn.getresponse()
    data = json.load(response)
    conn.close()
    return data
Ufx
  • 2,595
  • 12
  • 44
  • 83
  • Have you tried with `http.client` instead of `httplib2`? – Dalton Cézane Feb 16 '18 at 03:39
  • Replaced all `httplib` to `http.client`. Now I have error File "/usr/lib/python3.5/hmac.py", line 42, in __init__ raise TypeError("key: expected bytes or bytearray, but got %r" % type(key).__name__) TypeError: key: expected bytes or bytearray, but got 'str' . . But in Windows works well without `http.client`. – Ufx Feb 16 '18 at 03:48

0 Answers0