import requests class wechatapi(): def __init__(self): self.acess_token_url= "https://api.weixin.qq.com/cgi-bin/token" self.query_tag_url= "https://api.weixin.qq.com/cgi-bin/tags/get" self.edit_tag_url= "https://api.weixin.qq.com/cgi-bin/tags/update?access_token='tokenValue'" self.upload_doc_url= "https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=’tokenValue’" self.session= requests.Session() def acess_token_api(self): params = { "grant_type": "client_credential", "appid" : "wx8a9de038e93f77ab", "secret" : "8326fc915928dee3165720c910effb86" } reponse = self.session.get(url=self.acess_token_url,params=params) token = reponse.json()["access_token"] print(token) return token # def query_tag_api(self): # params= { # "access_token": "tokenValue" # } a = wechatapi a.acess_token_api()报错信息Traceback (most recent call last): File "D:\pythonProject1\WeChat\api\weChatApi.py", line 38, in <module> a.acess_token_api() TypeError: wechatapi.acess_token_api() missing 1 required positional argument: 'self'为什么报错,该怎样解决
时间: 2024-03-19 12:41:36 浏览: 201
这个错误是因为你在调用方法时没有传入实例对象本身,缺少了 `self` 参数。在调用 `acess_token_api()` 方法时,需要在实例对象 `a` 上调用,即 `a.acess_token_api()`。你可以将 `a = wechatapi` 修改为 `a = wechatapi()` 来实例化该类,然后再调用方法。
阅读全文