import datetime
import http
import python_http_client
import time
import random
from jose import jws
from jose.constants import ALGORITHMS
# from bitzlato import Bitzlato
# secret user key
key = {"kty":"EC","crv":"P-256","x":"KKKKKKKKKKS9REfefghTL_11sxrqA6s3OKQIgJ_BClM","y":"mQfffffeDDDDDFEEF-SpMa2kTJ1klw-op2NzgbtFaNg8","alg":"ES256"}
def main():
dt = datetime.datetime.now()
ts = time.mktime(dt.timetuple())
claims = {
# user identifier
"email": "email@gmail.com",
# leave as is
"aud": "usr",
# token issue time
"iat": int(ts),
# unique token identifier
"jti": hex(random.getrandbits(64))
}
print(claims)
# make token with claims from secret user key
# put the correct key id (kid)
token = jws.sign(claims, key, headers={"kid": "1"}, algorithm=ALGORITHMS.ES256)
conn = http.client.HTTPSConnection("www.bitzlato.com", 443)
# make request against api endpoint with Authorization: Bearer <token> header
res = conn.request("GET", "/api/auth/whoami", headers={
"Authorization": "Bearer " + token
})
r1 = conn.getresponse()
print(r1.status, r1.reason, r1.read())
if __name__ == '__main__':
main()
Traceback (most recent call last):
File "C:\Users\BLueface\AppData\Local\Programs\Python\Python310\lib\site-packages\jose\jws.py", line 161, in _sign_header_and_claims
signature = key.sign(signing_input)
File "C:\Users\BLueface\AppData\Local\Programs\Python\Python310\lib\site-packages\jose\backends\cryptography_backend.py", line 154, in sign
signature = self.prepared_key.sign(msg, ec.ECDSA(self.hash_alg()))
AttributeError: '_EllipticCurvePublicKey' object has no attribute 'sign'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\BLueface\Desktop\parser\btcbitzlato.py", line 42, in
main()
File "C:\Users\BLueface\Desktop\parser\btcbitzlato.py", line 30, in main
token = jws.sign(claims, key, headers={"kid": "1"}, algorithm=ALGORITHMS.ES256)
File "C:\Users\BLueface\AppData\Local\Programs\Python\Python310\lib\site-packages\jose\jws.py", line 43, in sign
signed_output = _sign_header_and_claims(encoded_header, encoded_payload, algorithm, key)
File "C:\Users\BLueface\AppData\Local\Programs\Python\Python310\lib\site-packages\jose\jws.py", line 163, in _sign_header_and_claims
raise JWSError(e)
jose.exceptions.JWSError: '_EllipticCurvePublicKey' object has no attribute 'sign'
Как исправить эту ошибку?