Python 我正在尝试创建一个HTTP post,但json返回“HTTP”;“讯息”:&引用;“未经授权”;

Python 我正在尝试创建一个HTTP post,但json返回“HTTP”;“讯息”:&引用;“未经授权”;,python,json,api,Python,Json,Api,授权书 URL受HTTP基本身份验证保护,RFC2617第2章对此进行了解释,因此您必须在POST请求中提供Authorization:header字段 对于HTTP基本身份验证的用户ID,请使用您在JSON字符串中输入的相同电子邮件地址。 对于密码,提供符合RFC6238 TOTP的10位基于时间的一次性密码 我还生成了密码,并使用哈希函数HMAC-SHA-512Hi Toufiqur,我面临着同样的问题,您是否发现了为什么这不起作用(@SuperKogito是的。使用postman,在授权下

授权书

URL受HTTP基本身份验证保护,RFC2617第2章对此进行了解释,因此您必须在POST请求中提供Authorization:header字段

对于HTTP基本身份验证的用户ID,请使用您在JSON字符串中输入的相同电子邮件地址。 对于密码,提供符合RFC6238 TOTP的10位基于时间的一次性密码


我还生成了密码,并使用哈希函数HMAC-SHA-512

Hi Toufiqur,我面临着同样的问题,您是否发现了为什么这不起作用(@SuperKogito是的。使用postman,在授权下查找基本身份验证并输入您的电子邮件id和随机密码…然后选择POST type并单击Send@ToufiqurRahman邮递员与巨蟒?@Math_复仇者你能说清楚你想知道什么吗?
import httplib2
import hmac
import hashlib
import time
import sys
import struct
import json

root = "https://api.challenge.hennge.com/challenges/003"
content_type = "application/json"
userid = "toufiqurrahman45@gmail.com"
name = "HENNGECHALLENGE003"
shared_secret = userid+name

timestep = 30
T0 = 0

def HOTP(K, C, digits=10):
    K_bytes = str.encode(K)
    C_bytes = struct.pack(">Q", C)
    hmac_sha512 = hmac.new(key = K_bytes, msg=C_bytes, digestmod=hashlib.sha512).hexdigest()
    return Truncate(hmac_sha512)[-digits:]

def Truncate(hmac_sha512):
    offset = int(hmac_sha512[-1], 16)
    binary = int(hmac_sha512[(offset *2):((offset*2)+8)], 16) & 0x7FFFFFFF
    return str(binary)

def TOTP(K, digits=10, timeref = 0, timestep = 30):
    C = int ( time.time() - timeref ) // timestep
    return HOTP(K, C, digits = digits)

data = { "github_url": "https://gist.github.com/TaufiqurRahman45/f5347e5ba6e7d24aa61ac8c78fda452e", "contact_email": "toufiqurrahman45@gmail.com" }

password = TOTP(shared_secret, 10, T0, timestep).zfill(10) 

h = httplib2.Http()
h.add_credentials( userid, password )
header = {"content-type": "application/json"}
resp, content = h.request(root, "POST", headers = header, body = json.dumps(data))
print(resp)
print(content)