python unresolved属性 - HTTPError

时间:2017-01-16 18:07:51

标签: python

使用pycharm(python 3)编写python程序,有部分程序:

class  GraphAPI(object):
    ...
    def get_version(self):
        '''Fetch the current version number of the Graph API being used'''
        args = {"access_token":self.access_token}
        try:
            response = self.request(
                "GET",
                FACEBOOK_GRAPH_URL + self.version + "/me",
                params = args,
                timeout = self.timeout,
                proxies = self.proxies
            )
        except requests.HTTPError as e:
            response = json.loads(e.read())
            raise GraphAPIError(response)

然而," e.read()"呈黄色,当鼠标移动时,显示:

Unresolved attribute reference 'read' for class 'HTTPError',This inspection     

detected names that should resolve but don't. Due to dynamic dispatch and   

duck typing, this is possible in a limited but useful number of cases.Top-

level and class-level items are supported better than instance items

1 个答案:

答案 0 :(得分:0)

pycharm告诉你它并不明白这个" e"请求类型.HTTPError确实有一个read()方法。

所以,很有可能,你只是错过了正确的import语句。你必须确保" name" requests.HTTPError为IDE所知。

(仅用于记录:pycharm通常对此类赋值是正确的,因此当pycharm为您提供该行的错误时,您的代码实际上存在问题并且将在运行时失败)