Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python “oAuth”;未提供密码,但私钥已加密;_Python_Python 3.x_Oauth_Jira - Fatal编程技术网

Python “oAuth”;未提供密码,但私钥已加密;

Python “oAuth”;未提供密码,但私钥已加密;,python,python-3.x,oauth,jira,Python,Python 3.x,Oauth,Jira,我正在为吉拉写一篇文章。但我得到的错误是“没有给出密码,但私钥是加密的”。我还试图用js实现这个解决方案,但遗憾的是它没有成功。现在我正在尝试python 我想调用Jira Rest API,为此我需要oAuth(以便通过代码创建Jira票据) 我的代码是: import requests from oauthlib.oauth1 import SIGNATURE_RSA from requests_oauthlib import OAuth1Session from jira.client i

我正在为吉拉写一篇文章。但我得到的错误是“没有给出密码,但私钥是加密的”。我还试图用js实现这个解决方案,但遗憾的是它没有成功。现在我正在尝试python

我想调用Jira Rest API,为此我需要oAuth(以便通过代码创建Jira票据)

我的代码是:

import requests
from oauthlib.oauth1 import SIGNATURE_RSA
from requests_oauthlib import OAuth1Session
from jira.client import JIRA

def read(file_path):
    #""" Read a file and return it's contents. """
    with open(file_path) as f:
        return f.read()

# The Consumer Key created while setting up the "Incoming Authentication" in
# JIRA for the Application Link.
CONSUMER_KEY = ('myconsumerkey')

# The contents of the rsa.pem file generated (the private RSA key)
RSA_KEY = read('myfilelink')

# The URLs for the JIRA instance
JIRA_SERVER = 'myjiralink'
REQUEST_TOKEN_URL = JIRA_SERVER + '/plugins/servlet/oauth/request-token'
AUTHORIZE_URL = JIRA_SERVER + '/plugins/servlet/oauth/authorize'
ACCESS_TOKEN_URL = JIRA_SERVER + '/plugins/servlet/oauth/access-token'


# Step 1: Get a request token

oauth = OAuth1Session(CONSUMER_KEY, signature_type='auth_header', 
                      signature_method=SIGNATURE_RSA, rsa_key=RSA_KEY)
request_token = oauth.fetch_request_token(REQUEST_TOKEN_URL)

print("STEP 1: GET REQUEST TOKEN")
print("  oauth_token={}".format(request_token['oauth_token']))
print("  oauth_token_secret={}".format(request_token['oauth_token_secret']))
print("\n")


# Step 2: Get the end-user's authorization

print("STEP2: AUTHORIZATION")
print("  Visit to the following URL to provide authorization:")
print("  {}?oauth_token={}".format(AUTHORIZE_URL, request_token['oauth_token']))
print("\n")

while input("Press any key to continue..."):
    pass


# Step 3: Get the access token

access_token = oauth.fetch_access_token(ACCESS_TOKEN_URL)

print("STEP2: GET ACCESS TOKEN")
print("  oauth_token={}".format(access_token['oauth_token']))
print("  oauth_token_secret={}".format(access_token['oauth_token_secret']))
print("\n")


# Now you can use the access tokens with the JIRA client. Hooray!

jira = JIRA(options={'server': JIRA_SERVER}, oauth={
    'access_token': access_token['oauth_token'],
    'access_token_secret': access_token['oauth_token_secret'],
    'consumer_key': CONSUMER_KEY,
    'key_cert': RSA_KEY
})

# print all of the project keys just as an exmaple
for project in jira.projects():
    print(project.key)

我解决了这个问题。问题是私钥受密码保护。现在,我移除了保护,它起作用了


下一步是使用密码私钥进行身份验证,但这是另一个问题。我将把这个问题标记为已解决

请不要发送代码的图像,它需要更长的时间来来回输入所有的东西,它是完全正确的方式。请用正确的格式代码编辑您的帖子。@ChristianKönig抱歉。我希望现在是oke@NaruS我编辑了它。我希望现在更好@TeslaX