Python 将httplib更改为http.client

Python 将httplib更改为http.client,python,httplib,Python,Httplib,我收到错误“没有名为httplib的模块”。然后我将httplib替换为http.client。我使用了2to3并在密钥前添加了b 现在我发现了一个错误 “非类型”对象不可下标 函数com不返回任何内容,即None。返回时,您尝试将选择运算符应用于None['fee'],这仅在com返回字典时有效。请包含完整的错误消息。已更新。这是另一个错误。那么,您实际看到了哪一个错误:“非类型”对象不可下标,或者Unicode对象必须在散列之前进行编码?已更新。 import http.client imp

我收到错误“没有名为httplib的模块”。然后我将httplib替换为http.client。我使用了2to3并在密钥前添加了b

现在我发现了一个错误

“非类型”对象不可下标


函数com不返回任何内容,即None。返回时,您尝试将选择运算符应用于None['fee'],这仅在com返回字典时有效。

请包含完整的错误消息。已更新。这是另一个错误。那么,您实际看到了哪一个错误:“非类型”对象不可下标,或者Unicode对象必须在散列之前进行编码?已更新。
import http.client
import urllib.request, urllib.parse, urllib.error
import json
import hashlib
import hmac
from collections import OrderedDict
import time

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


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

def post(url, params):
     conn = http.client.HTTPSConnection(server)
     data = OrderedDict(sorted(params))
     encoded_data = urllib.parse.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)

def com():
     conn = http.client.HTTPSConnection(server)
     sign = hmac.new(secret_key, b'', digestmod=hashlib.sha256).hexdigest().upper()
     headers = {"Api-key": api_key, "Sign": sign, "Content-type": "application/x-www-form-urlencoded"}
     conn.request("GET", "/ex/com", None, headers) 
Traceback (most recent call last):
  File "lc.py", line , in <module>
    COM = float(com()['fee'])
TypeError: 'NoneType' object is not subscriptable