#python-3.x #jwt #jira #access-token #jira-rest-api
Вопрос:
Привет, я пытаюсь подключиться к Jira, используя API с токеном OAuth. Но я получаю сообщение об ошибке ValueError: Не удалось десериализовать ключевые данные. при использовании сертификата publickey. Кто-нибудь может мне в этом помочь?
Ниже приведен код, который я использовал для доступа к Jira. Код:
from atlassian import Jira
from cryptography.hazmat.backends import default_backend
from cryptography import x509
key_cert_data = None
with open(r"C:pathjira_publickey.cer", 'rb') as key_cert_file:
key_cert_data = key_cert_file.read()
print(key_cert_data)
key_cert_file.close()
key = x509.load_pem_x509_certificate(key_cert_data, default_backend())
public_key = key.public_key()
print(public_key)
oauth_dict = {
'access_token': 'hskjfhejfhiwererhweuifh',
'access_token_secret': 'sSSK76',
'consumer_key': 'reyriuwrfjfhueyweur',
'key_cert': key_cert_data
}
jira_instance = Jira('https://jiraurl.aaaa.net/',oauth=oauth_dict)
Это обратная трассировка ошибок, которую я получил во время выполнения, я мог видеть, что оператор печати обоих работает нормально, но тогда я не понимаю, почему я получаю эту ошибку и не могу получить доступ к Jira.
Обратная связь:
b'-----BEGIN CERTIFICATE-----nuiwrwuhwbfjsdbdsbfdjfuwefwfff{actual key was there, hide while posting}==n-----END CERTIFICATE-----n'
<cryptography.hazmat.backends.openssl.rsa._RSAPublicKey object at 0x000001DASD46456SSD0>
Traceback (most recent call last):
File "C:PATHPythonPython38libsite-packagesjwtalgorithms.py", line 205, in prepare_key
key = load_pem_private_key(key, password=None, backend=default_backend())
File "C:PATHPythonPython38libsite-packagescryptographyhazmatprimitivesserializationbase.py", line 16, in load_pem_private_key return backend.load_pem_private_key(data, password)
File "C:PATHPythonPython38libsite-packagescryptographyhazmatbackendsopensslbackend.py", line 1085, in load_pem_private_key
return self._load_key(
File "C:PATHPythonPython38libsite-packagescryptographyhazmatbackendsopensslbackend.py", line 1315, in _load_key
self._handle_key_loading_error()
File "C:PATHPythonPython38libsite-packagescryptographyhazmatbackendsopensslbackend.py", line 1373, in _handle_key_loading_error
raise ValueError("Could not deserialize key data.")
ValueError: Could not deserialize key data.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:/PATH/main.py", line 458, in <module>
get_data_from_jira()
File "c:/PATH/main.py", line 87, in get_data_from_jira
data = jira_instance.jql("project = 'PROJECTNAME' AND issueType = 'ISSUETYPE' AND status = 'NEW')
File "C:PATHPythonPython38libsite-packagesatlassianjira.py", line 2289, in jql
return self.get("rest/api/2/search", params=params)
File "C:PATHPythonPython38libsite-packagesatlassianrest_client.py", line 264, in get
response = self.request(
File "C:PATHPythonPython38libsite-packagesatlassianrest_client.py", line 218, in request
response = self._session.request(
File "C:PATHPythonPython38libsite-packagesrequestssessions.py", line 516, in request
prep = self.prepare_request(req)
File "C:PATHPythonPython38libsite-packagesrequestssessions.py", line 449, in prepare_request
p.prepare(
File "C:PATHPythonPython38libsite-packagesrequestsmodels.py", line 318, in prepare
self.prepare_auth(auth, url)
File "C:PATHPythonPython38libsite-packagesrequestsmodels.py", line 549, in prepare_auth
r = auth(self)
File "C:PATHPythonPython38libsite-packagesrequests_oauthliboauth1_auth.py", line 108, in __call__
r.url, headers, _ = self.client.sign(
File "C:PATHPythonPython38libsite-packagesoauthliboauth1rfc5849__init__.py", line 313, in sign
('oauth_signature', self.get_oauth_signature(request)))
File "C:PATHPythonPython38libsite-packagesoauthliboauth1rfc5849__init__.py", line 148, in get_oauth_signature
sig = self.SIGNATURE_METHODS[self.signature_method](base_string, self)
File "C:PATHPythonPython38libsite-packagesoauthliboauth1rfc5849signature.py", line 592, in sign_rsa_sha1_with_client
return sign_rsa_sha1(base_string, client.rsa_key)
File "C:PATHPythonPython38libsite-packagesoauthliboauth1rfc5849signature.py", line 584, in sign_rsa_sha1
key = _prepare_key_plus(alg, rsa_private_key)
File "C:PATHPythonPython38libsite-packagesoauthliboauth1rfc5849signature.py", line 697, in _prepare_key_plus
return alg.prepare_key(keystr)
File "C:PATHPythonPython38libsite-packagesjwtalgorithms.py", line 207, in prepare_key
key = load_pem_public_key(key, backend=default_backend())
File "C:PATHPythonPython38libsite-packagescryptographyhazmatprimitivesserializationbase.py", line 20, in load_pem_public_key
return backend.load_pem_public_key(data)
File "C:PATHPythonPython38libsite-packagescryptographyhazmatbackendsopensslbackend.py", line 1115, in load_pem_public_key
self._handle_key_loading_error()
File "C:PATHPythonPython38libsite-packagescryptographyhazmatbackendsopensslbackend.py", line 1373, in _handle_key_loading_error
raise ValueError("Could not deserialize key data.")
ValueError: Could not deserialize key data.