Python问题:AttributeError:'dict'对象没有属性'upper'

eri*_*ric 2 python twitter google-app-engine

尝试发布推文时,我从AppEngine收到此错误.我觉得我的语法不对,但我现在不知所措.

对于我的生活,我似乎无法使用以下命令将我的状态参数发送到post函数中的**extra_params:

args = {} <br/>
args.update({'status': 'THIS IS MY TWEET'})<br/>
info2 = client.post('/statuses/update',args)<br/>
Run Code Online (Sandbox Code Playgroud)

确切的错误是:

"File "/base/data/home/apps/kymbatweet/1.350119792863170339/main.py", line 311, in get_signed_body
    __meth.upper(), __url, '&'.join(
AttributeError: 'dict' object has no attribute 'upper'"
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?(代码如下)

    def post(self, api_method, http_method='POST', expected_status=(200,), **extra_params):

        if not (api_method.startswith('http://') or api_method.startswith('https://')):
            api_method = '%s%s%s' % (
                self.service_info['default_api_prefix'], api_method,
                self.service_info['default_api_suffix']
                )

        if self.token is None:
            #self.token = OAuthAccessToken.get_by_key_name(self.get_cookie())
            self.token = "000"



        fetch = urlfetch(url=api_method, payload=self.get_signed_body(
            api_method, "000", http_method, **extra_params
            ), method=http_method)

        if fetch.status_code not in expected_status:
            raise ValueError(
                "Error calling... Got return status: %i [%r]" %
                (fetch.status_code, fetch.content)
                )

        return decode_json(fetch.content)



    def get_signed_body(self, __url, __token=None, __meth='GET',**extra_params):

        service_info = self.service_info

        kwargs = {
            'oauth_consumer_key': service_info['consumer_key'],
            'oauth_signature_method': 'HMAC-SHA1',
            'oauth_version': '1.0',
            'oauth_timestamp': int(time()),
            'oauth_nonce': getrandbits(64),
            }

        kwargs.update(**extra_params)
        #This works if hardcoded
        #kwargs.update({'status': 'AE'})

        if self.service_key is None:
            self.service_key = get_service_key(self.service)

        if __token is not None:
            kwargs['oauth_token'] = "000"
            key = self.service_key + encode("6iD2LYnUfEOYl0zOCj5IKawbok3pjs4yixay5bdM")
        else:
            key = self.service_key
        #Code BOMBS HERE
        message = '&'.join(map(encode, [
            __meth.upper(), __url, '&'.join(
                '%s=%s' % (encode(k), encode(kwargs[k])) for k in sorted(kwargs)
                )
            ]))

        kwargs['oauth_signature'] = hmac(
            key, message, sha1
            ).digest().encode('base64')[:-1]

        return urlencode(kwargs)



class MainHandler(RequestHandler):
    """Demo Twitter App."""

    def get(self):

        client = OAuthClient('twitter', self)

        client.token = "000"


        args = {}
        args.update({'status': 'THIS IS MY TWEET'})

        info2 = client.post('/statuses/update',args)
Run Code Online (Sandbox Code Playgroud)

Ign*_*ams 6

你没有传递它,因为extra_params你传递它http_method.

info2 = client.post('/statuses/update', **args)
Run Code Online (Sandbox Code Playgroud)