I'm using python3 requests module to access Github v3 API (DELETE /user/keys/:key_id) of the deleting public ssh-key that it return the error

{'message': 'Not Found''documentation_url':'https://developer.github.com/v3'}.

I use python3 virtual environmemt and requests module to handle. I checked the URL and method of the api and it has no problem. In addition, I added access_token='My token' after the URL parameter. but no effect. i try to use command curl -H "Authorization: token 93ca7d685602dca9d32e8788ddffafc8e7385003" https://api.github.com/users/codertocat -I to find the scope of the token. and I checked that the the key_id is correct also.

    def __init__(self):
        self.accessToken = '93ca7d685602dca9d32e8788ddffafc8e7385003'
        self.rootUrl = 'https://api.github.com'
        self.headers = {"Authorization": "token %s" % self.accessToken}

    def baseGet(self, url, me='get', data=None):
        try:
            response = ''
            if me == 'get':
                response = requests.get(url)
            if me == 'post':
                response = requests.get(url, data)
            if me == 'delete':
                response = requests.delete(url)
            else:
                print('no support')
            try:
                data = response.json()
            except:
                data = response.content
            return data
        except Exception as e:
            print('error by', e)
            return False

    def del_user_public_key(self, key_id):
        # del_user_public_key
        userkey = self.rootUrl + '/users/keys/%d?access_token=%s' % (key_id, self.accessToken)
        print(userkey)
        return self.baseGet(userkey, me='delete')

I expect the output of the result to be Status 204 No Content and the public deleted in github.

0 Answers