1

我正在尝试如下:

SSHKEY=`cat ~/.ssh/id_rsa.pub`
curl -u username:password -X POST -H "Content-Type: application/json" -d '{"key": "$SSHKEY", "label": "someLabel"}' https://api.bitbucket.org/2.0/users/username/ssh-keys

但它给出了:

{"type": "error", "error": {"fields": {"key": ["That SSH key is invalid."]}, "message": "key: That SSH key is invalid."}}

关于如何使用 api 将此 ssh 密钥发送到 bitbucket 的任何想法?

4

1 回答 1

1

好的,我使用 python 3 脚本使它工作。

#!/usr/bin/python3
import os
import requests, json

url = "https://api.bitbucket.org/2.0/users/userName/ssh-keys"

key = open(os.path.expanduser('~/.ssh/id_rsa.pub')).read()
print(key)

payload = {
        "key": key, 
        "label": "testSSHKey"
       }

header = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} 

response_decoded_json = requests.post(url, auth=requests.auth.HTTPBasicAuth('userName', 'password'), data=payload, headers=header)
response_json = response_decoded_json.json()

print(response_json)
于 2019-03-17T04:21:17.470 回答