我想在JSON响应中发送我的作业(job)要点:

推荐答案

虽然你必须自己做,但如果你投入了大量时间,但没有找到解决方案,那么你可以使用我的解决方案:

import requests
import hmac
import hashlib
import time
import sys
import struct
import json

from requests.auth import HTTPBasicAuth

root = "YOUR API RESIDES HERE"
content_type = "application/json"
userid = "YOUR USERID"
secret_suffix = "YOUR SECRET SUFFIX OR KEY"
shared_secret = userid+secret_suffix

timestep = 30
T0 = 0

def HOTP(K, C, digits=10):
    """HTOP:
    K is the shared key
    C is the counter value
    digits control the response length
    """
    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):
    """truncate sha512 value"""
    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):
    """TOTP, time-based variant of HOTP
    digits control the response length
    the C in HOTP is replaced by ( (currentTime - timeref) / timestep )
    """
    C = int ( time.time() - timeref ) // timestep
    return HOTP(K, C, digits = digits)

data = {
  "github_url": "YOUR GITHUB URL",
  "contact_email": "YOUR EMAIL",
  "solution_language": "IT IS OPTIONAL"
}
passwd = TOTP(shared_secret, 10, T0, timestep).zfill(10) 
resp = requests.post(root, auth=HTTPBasicAuth(userid, passwd), data=json.dumps(data))
print(resp.json())

我希望这能奏效!!

Python相关问答推荐

Polars将相同的自定义函数应用于组中的多个列,

ruamel.yaml dump:如何阻止map标量值被移动到一个新的缩进行?

Python pint将1/华氏度转换为1/摄氏度°°

如何在一组行中找到循环?

BeatuifulSoup从欧洲志愿者服务中获取数据和解析:一个从EU-Site收集机会的小铲子

PYTHON中的selenium不会打开 chromium URL

如果列包含空值,则PANAS查询不起作用

如何使用count()获取特定日期之间的项目

如何从NumPy数组中提取主频?

我应该使用哪一个来判断python中枚举值的唯一性?

属性错误:';Styler';对象没有属性';样式';

将Pandas 中的一组名字与其他一组带数字的名字进行匹配

如何拟合返回2个输出的深度学习模型

PANDA TO_DICT-按键列出行(_D)

Python拟合线到高维点并在它们之间采样

基于直方图箱的样本数据

允许在枚举中使用一组特定的未定义值

如何从polars中的列表中 Select 所有列

Pandas 多列数据帧的重采样和内插

PythonRequests.get以不同的编码提供响应