我有一个有效的user_id,还有一个管理令牌(存储在GITLAB_ADMIN_TOKEN中)
但是当我按照Python运行添加用户ID的SSH密钥时,我收到404错误。
# Add SSH Key
url = 'http://114.xx.xx.xx:8080/api/v3/users/' + str(user_id)+ '/keys?private_token=' + GITLAB_ADMIN_TOKEN
print url
values = {'id':user_id,
'title':'mykey',
'key':'ssh-rsa xxxxxxxxxxxxxxxxx ..... root@ubuntu'}
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
the_page = response.read()
print the_page
结果是: http://114.xx.xx.xx:8080/api/v3/users/30/keys?private_token=xxxxxx
Traceback (most recent call last): File "testgitlab.py", line 61, in response = urllib2.urlopen(req) File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen return _opener.open(url, data, timeout) File "/usr/lib/python2.7/urllib2.py", line 410, in open response = meth(req, response) File "/usr/lib/python2.7/urllib2.py", line 523, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python2.7/urllib2.py", line 448, in error return self._call_chain(*args) File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain result = func(*args) File "/usr/lib/python2.7/urllib2.py", line 531, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 404: Not Found
答案 0 :(得分:2)
我知道现在的问题在哪里。 在我最初的实现中,我用
粘贴了密钥 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCrTAR1MVs1juu1MuZ8C09CZpxm56hDzguRGuenmHez7Co9NQyx3GKLa5ksfdMNk+OBLVuf/fFZZ1ZoFGH9Cz/xNkxwtzjd6UiTt/6ECO9rClYK3LfX5RTv7a2O9zxhsudpofhIkUS0fYFmRlTi/htssbU5IC+U1i+xXHvfBChdLd2EasakGB89+Sw5t74cVyMiC8mRkcLxpCRI1BPEQd5FRZQr8piQxW2APcWnT7h18gY1F9qm50pq2PQgk7rQtkLMQKVVu30/95W7IBVfTMfklnDk3z0Dj4EcqzKYeeenwVn6YdC3fI5ZmLTpNhLlLwJPlBDQnUSIn8pBrmXfpPy7 root@ubuntu
但root@ubuntu
不应包括在内。当我从2048-bit
键中删除它时,它现在可以正常工作。