Giter Club home page Giter Club logo

itchatmp's People

Contributors

littlecodersh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

itchatmp's Issues

在无自主权限的情况下,能不能回复两次

个人订阅号无发送消息接口权限,只能回复,可看样子微信只会来访问一次第三方服务器,这样做得到么
我:测试
公众号:请 稍后
5秒后
公众号:XXXXXXX
在没有直接发送消息的权限下

请问例子中的"yourToken"指的是哪种token?

不好意思打扰了,这个问题可能很幼稚,但刚入门搞公众号,确实有点没懂。

想请教的是,贵项目readme中提到的这个“yourToken”是指的哪种token呢?

代码是这个:

itchatmp.update_config(itchatmp.WechatConfig(
    token='yourToken',
    appId = 'yourAppId',
    appSecret = 'yourAppSecret'))

关于可以回复的内容

请问itchatmp能回复的内容是不是只包含IMAGE, VOICE, VIDEO, TEXT, NEWS, CARD,能否简单介绍一下IMAGE图片格式以及NEWS该如何发送,代码看的不是很懂。
多谢了。
是否可以发送doc文件。

不知道为什么会有thread的bug。。。

/usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings InsecureRequestWarning) Uncaught exception POST /?signature=66bd3f677364c353d9b986e4b0005f3e86d2c97f&timestamp=1539071870&nonce=797132558&openid=obYqI1KyGRMh52u_eS1_33pEPYtk (127.0.0.1) HTTPServerRequest(protocol='http', host='raspberrypitest.natapp1.cc', method='POST', uri='/?signature=66bd3f677364c353d9b986e4b0005f3e86d2c97f&timestamp=1539071870&nonce=797132558&openid=obYqI1KyGRMh52u_eS1_33pEPYtk', version='HTTP/1.1', remote_ip='127.0.0.1') Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/tornado/web.py", line 1592, in _execute result = yield result File "/usr/local/lib/python3.5/dist-packages/tornado/gen.py", line 1133, in run value = future.result() File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result raise self._exception File "/usr/local/lib/python3.5/dist-packages/tornado/gen.py", line 1141, in run yielded = self.gen.throw(*exc_info) File "/usr/local/lib/python3.5/dist-packages/itchatmp/components/register.py", line 231, in post r, rawReply = yield threadPool.submit(post_fn, self) File "/usr/local/lib/python3.5/dist-packages/tornado/gen.py", line 1133, in run value = future.result() File "/usr/lib/python3.5/concurrent/futures/_base.py", line 398, in result return self.__get_result() File "/usr/lib/python3.5/concurrent/futures/_base.py", line 357, in __get_result raise self._exception File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run result = self.fn(*self.args, **self.kwargs) File "/usr/local/lib/python3.5/dist-packages/itchatmp/components/register.py", line 61, in sync_post_fn return verify_reply(core, tns, reply, msgDict, isActualEncrypt) File "/usr/local/lib/python3.5/dist-packages/itchatmp/components/register.py", line 165, in verify_reply r = core.upload(reply['MsgType'], reply['FileDir']) File "/usr/local/lib/python3.5/dist-packages/itchatmp/controllers/messages.py", line 34, in upload fileType, fileDir, additionalDict, permanent) File "/usr/local/lib/python3.5/dist-packages/itchatmp/controllers/common.py", line 19, in determine_wrapper return mpFn(*args, **kwargs) File "/usr/local/lib/python3.5/dist-packages/itchatmp/controllers/mpapi/base/common.py", line 147, in __access_token updateResult = tokenFn() File "/usr/local/lib/python3.5/dist-packages/itchatmp/controllers/mpapi/base/common.py", line 82, in _update_access_token r = ReturnValue(r) File "/usr/local/lib/python3.5/dist-packages/itchatmp/returnvalues.py", line 30, in __init__ Future.__init__(self) File "/usr/lib/python3.5/asyncio/futures.py", line 169, in __init__ self._loop = events.get_event_loop() File "/usr/lib/python3.5/asyncio/events.py", line 671, in get_event_loop return get_event_loop_policy().get_event_loop() File "/usr/lib/python3.5/asyncio/events.py", line 583, in get_event_loop % threading.current_thread().name) RuntimeError: There is no current event loop in thread 'Thread-1'.
我只是想回图片给发过来的人,然后就一直报这个错,感觉像是没办法创建新的进程?
`@itchatmp.msg_register(itchatmp.content.TEXT)
def text_reply(msg):
print(msg)
return '@[email protected]'

itchatmp.run()`

怎么能下载语音呢?

语音的msg打印出来是这个样子,我怎么才能下载呢?
{'MediaId': 'T6Z9To4GYCkOh1cmmj5nlPWKaAo_9nGBwvrmdk7aTuAbRZfD2vwEPwKoRFBivE5g', 'Format': 'amr', 'MsgId': '6588671912087535420', 'ToUserName': 'gh_84236748f295', 'MsgType': 'voice', 'FromUserName': 'o4sRa01xWBybCQ-OA3L4wO_Jxxxx', 'CreateTime': '1534044722', 'Recognition': {}}

服务器经常出现 TypeError: send() takes at least 2 arguments (1 given)

Uncaught exception POST /?signature=96e4cea608b71070e6a4a71a66d20b38b79dca8b&timestamp=1489068324&nonce=1809922204&openid=ooQn8wMiWdUAPsctsTYI5PcYUL7Y (58.247.206.151)
HTTPServerRequest(protocol='http', host='101.37.24.45', method='POST', uri='/?signature=96e4cea608b71070e6a4a71a66d20b38b79dca8b&timestamp=1489068324&nonce=1809922204&openid=ooQn8wMiWdUAPsctsTYI5PcYUL7Y', version='HTTP/1.1', remote_ip='58.247.206.151', headers={'Content-Length': '277', 'Accept': '*/*', 'User-Agent': 'Mozilla/4.0', 'Host': '101.37.24.45', 'Pragma': 'no-cache', 'Content-Type': 'text/xml'})
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 1469, in _execute
    result = yield result
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 1015, in run
    value = future.result()
  File "/usr/local/lib/python2.7/dist-packages/tornado/concurrent.py", line 237, in result
    raise_exc_info(self._exc_info)
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 1021, in run
    yielded = self.gen.throw(*exc_info)
  File "build/bdist.linux-x86_64/egg/itchatmp/components/register.py", line 236, in post
    (rawReply, rawReply.get('ToUserName', '')))
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 1015, in run
    value = future.result()
  File "/usr/local/lib/python2.7/dist-packages/concurrent/futures/_base.py", line 398, in result
    return self.__get_result()
  File "/usr/local/lib/python2.7/dist-packages/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
TypeError: send() takes at least 2 arguments (1 given)

无法发送文字回复?

如题,刚试了一下您的示例代码,确认APPID等无误后,在return前加了一行“print(msg[Content])”,然后我试图给该公众号发消息,服务端就报异常,内容如下

比如我下方输入“Ymml”,可见第三行服务端确实已经收到了数据。但是无法实现自动回复。

root@vultr:~/WeChatAtis# python3 wechat_bot.py
itchatmp started! press Ctrl+C to exit.
Ymml
Uncaught exception POST /?signature=xyz&timestamp=1492143218&nonce=153459053&openid=xyzxBFrI&encrypt_type=aes&msg_signature=12xyzc6c95f0a3da479dd (103.7.30.69)
HTTPServerRequest(protocol='http', host='45.63.xyz.xyz', method='POST', uri='/?signature=xyz&timestamp=1492143218&nonce=153459053&openid=xyzxBFrI&encrypt_type=aes&msg_signature=12xyzc6c95f0a3da479dd', version='HTTP/1.1', remote_ip='103.7.30.69', headers={'Accept': '*/*', 'Content-Type': 'text/xml', 'User-Agent': 'Mozilla/4.0', 'Content-Length': '767', 'Pragma': 'no-cache', 'Host': '45.63.xyz.xyz'})
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/itchatmp/views/msgconstruct.py", line 89, in _render
    return template.format(**replyDict)
KeyError: 'Content'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/tornado/web.py", line 1469, in _execute
    result = yield result
  File "/usr/local/lib/python3.4/dist-packages/tornado/gen.py", line 1015, in run
    value = future.result()
  File "/usr/local/lib/python3.4/dist-packages/tornado/concurrent.py", line 237, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 3, in raise_exc_info
  File "/usr/local/lib/python3.4/dist-packages/tornado/gen.py", line 1021, in run
    yielded = self.gen.throw(*exc_info)
  File "/usr/local/lib/python3.4/dist-packages/itchatmp/components/register.py", line 231, in post
    r, rawReply = yield threadPool.submit(post_fn, self)
  File "/usr/local/lib/python3.4/dist-packages/tornado/gen.py", line 1015, in run
    value = future.result()
  File "/usr/lib/python3.4/concurrent/futures/_base.py", line 395, in result
    return self.__get_result()
  File "/usr/lib/python3.4/concurrent/futures/_base.py", line 354, in __get_result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.4/dist-packages/itchatmp/components/register.py", line 61, in sync_post_fn
    return verify_reply(core, tns, reply, msgDict, isActualEncrypt)
  File "/usr/local/lib/python3.4/dist-packages/itchatmp/components/register.py", line 174, in verify_reply
    return construct_msg(reply), reply
  File "/usr/local/lib/python3.4/dist-packages/itchatmp/views/msgconstruct.py", line 117, in construct_msg
    return _render(get_template(replyDict['MsgType']), replyDict)
  File "/usr/local/lib/python3.4/dist-packages/itchatmp/views/msgconstruct.py", line 91, in _render
    logger.debug('Missing message element "%s"' % e.message)
AttributeError: 'KeyError' object has no attribute 'message'
500 POST /?signature=xyz&timestamp=1492143218&nonce=153459053&openid=xyzxBFrI&encrypt_type=aes&msg_signature=12xyzc6c95f0a3da479dd (103.7.30.69) 21.84ms
Exception in callback functools.partial(<function wrap.<locals>.null_wrapper at 0x7fdcf0c61598>)
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/tornado/ioloop.py", line 604, in _run_callback
    ret = callback()
  File "/usr/local/lib/python3.4/dist-packages/tornado/stack_context.py", line 275, in null_wrapper
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/itchatmp/components/register.py", line 227, in time_out_callback
    self.finish()
  File "/usr/local/lib/python3.4/dist-packages/tornado/web.py", line 923, in finish
    raise RuntimeError("finish() called twice")
RuntimeError: finish() called twice

这个项目已经不维护了吗? python3.7似乎不兼容

python3.7 使用pipenv 安装报错

pipenv install itchatmp

Installing itchatmp… Adding itchatmp to Pipfile's [packages]… ✔ Installation Succeeded Pipfile.lock (c896b0) out of date, updating to (889585)… Locking [dev-packages] dependencies… Locking [packages] dependencies… ✘ Locking Failed! Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/resolver.py", line 126, in <module> main() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/resolver.py", line 119, in main parsed.requirements_dir, parsed.packages) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/resolver.py", line 85, in _main requirements_dir=requirements_dir, File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/resolver.py", line 69, in resolve req_dir=requirements_dir File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/utils.py", line 726, in resolve_deps req_dir=req_dir, File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/utils.py", line 480, in actually_resolve_deps resolved_tree = resolver.resolve() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/utils.py", line 385, in resolve results = self.resolver.resolve(max_rounds=environments.PIPENV_MAX_ROUNDS) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/patched/piptools/resolver.py", line 102, in resolve has_changed, best_matches = self._resolve_one_round() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/patched/piptools/resolver.py", line 206, in _resolve_one_round for dep in self._iter_dependencies(best_match): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/patched/piptools/resolver.py", line 301, in _iter_dependencies dependencies = self.repository.get_dependencies(ireq) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/patched/piptools/repositories/pypi.py", line 234, in get_dependencies legacy_results = self.get_legacy_dependencies(ireq) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/patched/piptools/repositories/pypi.py", line 426, in get_legacy_dependencies results, ireq = self.resolve_reqs(download_dir, ireq, wheel_cache) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/patched/piptools/repositories/pypi.py", line 297, in resolve_reqs results = resolver._resolve_one(reqset, ireq) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/patched/notpip/_internal/resolve.py", line 274, in _resolve_one self.requires_python = check_dist_requires_python(dist, absorb=False) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/patched/notpip/_internal/utils/packaging.py", line 62, in check_dist_requires_python '.'.join(map(str, sys.version_info[:3])),) pipenv.patched.notpip._internal.exceptions.UnsupportedPythonVersion: futures requires Python '>=2.6, <3' but the running Python is 3.7.1 File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/resolver.py", line 126, in <module> main() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/resolver.py", line 119, in main parsed.requirements_dir, parsed.packages) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/resolver.py", line 85, in _main requirements_dir=requirements_dir, File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/resolver.py", line 69, in resolve req_dir=requirements_dir File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/utils.py", line 726, in resolve_deps req_dir=req_dir, File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/utils.py", line 480, in actually_resolve_deps resolved_tree = resolver.resolve() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/utils.py", line 385, in resolve results = self.resolver.resolve(max_rounds=environments.PIPENV_MAX_ROUNDS) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/patched/piptools/resolver.py", line 102, in resolve has_changed, best_matches = self._resolve_one_round() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/patched/piptools/resolver.py", line 206, in _resolve_one_round for dep in self._iter_dependencies(best_match): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/patched/piptools/resolver.py", line 301, in _iter_dependencies dependencies = self.repository.get_dependencies(ireq) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/patched/piptools/repositories/pypi.py", line 234, in get_dependencies legacy_results = self.get_legacy_dependencies(ireq) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/patched/piptools/repositories/pypi.py", line 426, in get_legacy_dependencies results, ireq = self.resolve_reqs(download_dir, ireq, wheel_cache) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/patched/piptools/repositories/pypi.py", line 297, in resolve_reqs results = resolver._resolve_one(reqset, ireq) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/patched/notpip/_internal/resolve.py", line 274, in _resolve_one self.requires_python = check_dist_requires_python(dist, absorb=False) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/patched/notpip/_internal/utils/packaging.py", line 62, in check_dist_requires_python '.'.join(map(str, sys.version_info[:3])),) pipenv.patched.notpip._internal.exceptions.UnsupportedPythonVersion: futures requires Python '>=2.6, <3' but the running Python is 3.7.1

这种情况怎么处理the SSL module is not available?

SSLError: HTTPSConnectionPool(host='api.weixin.qq.com', port=443): Max retries exceeded with url: /cgi-bin/token?grant_type=client_credential&appid=w4195***&secret=3c4e***(Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",))

filter Request non functional

过滤非微信服务器信息

itchatmp.update_config(filterRequest=True)

使用以后 微信公众号不能被动回复了。

自定义路由改进

我修改了 \itchatmp\components\register.py 文件中的run函数,添加了一个自定义的url参数,修改代码如下:
def run(self, isWsgi=False, debug=True, port=80, url='/'):
self.isWsgi = isWsgi
self.debug = debug
if debug:
set_logging(loggingLevel=logging.DEBUG)
MainHandler = construct_handler(self, isWsgi)
app = tornado.web.Application(
[(url, MainHandler)], debug=debug)
添加这个url参数,主要是在实际应用中,我使用nginx做代理,微信公众号服务器地址有二级路径,例如:http://vfczq9.natappfree.cc/yl
希望这个功能可以添加到主版本中,目前我是fork了一个版本:https://github.com/dlyili/itchatmp

非常感谢。

微信接口变化了:用户unionID获取策略调整

用户unionID获取策略调整,请开发者注意更新
为保护用户隐私,用户unionID需用户主动授权或关注公众号后才可获得,微信公众号接口将做以下调整:

1、微信授权登录功能中的换取access_token接口

https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
本接口在scope参数为snsapi_base时不再提供unionID字段。

调整建议:

只需将scope参数修改为snsapi_userinfo即可重新获得用户unionID。

详情可参考微信授权登录文档

2、获取用户基本信息接口

https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN
https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=ACCESS_TOKEN
本接口在用户未关注公众号时,将不返回用户unionID信息。

调整建议:

已关注的用户,开发者可使用“获取用户基本信息接口”获取unionID;

未关注用户,开发者可使用“微信授权登录接口”并将scope参数设置为snsapi_userinfo,获取用户unionID

详情可参考获取用户基本信息接口文档

以上变更将在2017年12月31日之前逐步生效,请开发者尽快更新。​

微信团队
2017年12月13日

用测试范例启动监听进程,但是在微信企业号输入查询信息后出错

Uncaught exception POST /?msg_signature=40dcd2742816654fd287921499cb4f58e0d90ba2&timestamp=1575255735&nonce=1575079741 (xx.xx.xx.xx)
HTTPServerRequest(protocol='http', host='xx.xx.xx.xx:8080', method='POST', uri='/?msg_signature=40dcd2742816654fd287921499cb4f58e0d90ba2&timestamp=1575255735&nonce=1575079741', version='HTTP/1.1', remote_ip=xx.xx.xx.xx')

其中xx.xx.xx.xx是ip地址

测试环境是CentOS7,python3.6
tornado是手动安装的,指定了5.1版本
然后python3 -m pip install itchatmp来安装系统包
使用官方代码,只是改了连接信息

import itchatmp
from tornado import gen

itchatmp.update_config(itchatmp.WechatConfig(
token='xxxxxxxxxx',
copId = 'xxxxxxxxxx',
appSecret = 'xxxxxxxxxx',
encryptMode=itchatmp.content.SAFE,
encodingAesKey='xxxxxxxxxx',))

@itchatmp.msg_register(itchatmp.content.TEXT)
def text_reply(msg):
yield gen.sleep(3)
r = yield itchatmp.send('First message', msg['FromUserName'])
print('First message sent: %s' % r)
yield gen.sleep(3)
r = yield itchatmp.send('First message', msg['FromUserName'])
print('Second message sent: %s' % r)

itchatmp.run(port=8080)

发送消息报错

    • [2019/08/11 11:53:08] aihelper 570 1 - Traceback (most recent call last):\n File "/data1/www/htdocs/570/aihelper/1/vendor/itchatmp/components/register.py", line 56, in sync_post_fn\n reply = reply_fn(copy.deepcopy(msgDict))\n File "/data1/www/htdocs/570/aihelper/1/main.py", line 28, in reply\n itchatmp.send('Hello', msg['FromUserName'])\n File "/data1/www/htdocs/570/aihelper/1/vendor/itchatmp/controllers/wrapped.py", line 9, in send\n msg, toUserName, mediaId)\n File "/data1/www/htdocs/570/aihelper/1/vendor/itchatmp/controllers/common.py", line 19, in determine_wrapper\n return mpFn(*args, **kwargs)\n File "/data1/www/htdocs/570/aihelper/1/vendor/itchatmp/controllers/mpapi/mp/wrapped.py", line 70, in send\n r = cssend(msgType, mediaId, additionalDict=msg, toUserId=toUserId)\n File "/data1/www/htdocs/570/aihelper/1/vendor/itchatmp/controllers/mpapi/base/common.py", line 147, in __access_token\n updateResult = tokenFn()\n File "/data1/www/htdocs/570/aihelper/1/vendor/itchatmp/controllers/mpapi/base/common.py", line 78, in _update_access_token\n r['access_token'], int(time.time()) + r['expires_in'])\n File "/data1/www/htdocs/570/aihelper/1/vendor/itchatmp/models/common.py", line 63, in store_access_token\n self.__storage.set('accessToken', (accessToken, expireTime))\nMemcachedError: error 47 from memcached_set: SERVER HAS FAILED AND IS DISABLED UNTIL TIMED RETRY hwbj171
    • [2019/08/11 11:53:08] aihelper 570 1

文档中,生成二维码部分说明有误

关于数据,如果你的二维码是会过期的,那数据可以是字符串或者是数字。

否则的话只能是数字。

实际情况是相反的,如果二维码是永久二维码,才可以使用字符串,看了itchatmp源码也是这样实现的

下载图片时出错?

脚本里有
file=itchatmp.messages.download(msg['MediaId']),
收到图片时会发生下面的错误。
在 Python2.7 是没问题的,
出问题是在3.5.5。
有人知道解决方法吗

在附上我的 requirements.txt

File "/root/anaconda3/envs/itchatmp/lib/python3.5/site-packages/itchatmp/components/register.py", line 56, in sync_post_fn
reply = reply_fn(copy.deepcopy(msgDict))
File "app.py", line 143, in img_reply
file=itchatmp.messages.download(msg['MediaId'])
File "/root/anaconda3/envs/itchatmp/lib/python3.5/site-packages/itchatmp/controllers/messages.py", line 38, in download
mediaId)

File "/root/anaconda3/envs/itchatmp/lib/python3.5/site-packages/itchatmp/controllers/common.py", line 19, in determine_wrapper
**return mpFn(*args, kwargs)
File "/root/anaconda3/envs/itchatmp/lib/python3.5/site-packages/itchatmp/controllers/mpapi/base/common.py", line 147, in __access_token
updateResult = tokenFn()

File "/root/anaconda3/envs/itchatmp/lib/python3.5/site-packages/itchatmp/controllers/mpapi/base/common.py", line 80, in _update_access_token
r = ReturnValue(r)

File "/root/anaconda3/envs/itchatmp/lib/python3.5/site-packages/itchatmp/returnvalues.py", line 30, in init
Future.init(self)
File "/root/anaconda3/envs/itchatmp/lib/python3.5/asyncio/futures.py", line 169, in init
self._loop = events.get_event_loop()

File "/root/anaconda3/envs/itchatmp/lib/python3.5/asyncio/events.py", line 678, in get_event_loop
return get_event_loop_policy().get_event_loop()

File "/root/anaconda3/envs/itchatmp/lib/python3.5/asyncio/events.py", line 584, in get_event_loop
% threading.current_thread().name)

RuntimeError: There is no current event loop in thread 'Thread-9'.

asn1crypto==0.24.0
certifi==2018.4.16
cffi==1.11.5
chardet==3.0.4
cryptography==2.2.2
future==0.16.0
futures==3.1.1
idna==2.6
itchatmp==0.0.17
Pillow==5.1.0
pycparser==2.18
pylibmc==1.5.2
PyMySQL==0.8.0
python-memcached==1.59
pyzbar==0.1.5
requests==2.18.4
six==1.11.0
tornado==5.0.2
urllib3==1.22

$ pip install itchatmp
Requirement already satisfied: itchatmp in /python3.5/site-packages (0.0.17)
Requirement already satisfied: futures in /python3.5/site-packages (from itchatmp) (3.1.1)
Requirement already satisfied: tornado in /python3.5/site-packages (from itchatmp) (5.0.2)
Requirement already satisfied: cryptography in /python3.5/site-packages (from itchatmp) (2.2.2)
Requirement already satisfied: requests in /python3.5/site-packages (from itchatmp) (2.18.4)
Requirement already satisfied: six>=1.4.1 in /python3.5/site-packages (from cryptography->itchatmp) (1.11.0)
Requirement already satisfied: asn1crypto>=0.21.0 in /python3.5/site-packages (from cryptography->itchatmp) (0.24.0)
Requirement already satisfied: cffi>=1.7; platform_python_implementation != "PyPy" in /python3.5/site-packages (from cryptography->itchatmp) (1.11.5)
Requirement already satisfied: idna>=2.1 in /python3.5/site-packages (from cryptography->itchatmp) (2.6)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /python3.5/site-packages (from requests->itchatmp) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /python3.5/site-packages (from requests->itchatmp) (2018.4.16)
Requirement already satisfied: urllib3<1.23,>=1.21.1 in /python3.5/site-packages (from requests->itchatmp) (1.22)
Requirement already satisfied: pycparser in /python3.5/site-packages (from cffi>=1.7; platform_python_implementation != "PyPy"->cryptography->itchatmp) (2.18)

找不到群聊

Linux
hotReload=True
itchat.run()

使用 itchat.search_chatrooms('2017') 搜索群聊列表含有 2017 字段的群聊时,找不到对应的群聊;
使用 itchat.get_chatrooms(update=True) 更新群聊列表时,获取的群聊数量也小于实际数量;

强制使用80端口

服务器上的80端口是由 caddy 进行反向代理的,所以无法使用80端口。可否在配置监听其他端口呢?

pip3安装失败

python版本为3.4/3.5都试过了,pip3安装失败,报错的话是Command "/usr/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-build-q1togphe/cryptography/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-tfkym70u-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-q1togphe/cryptography/

ubuntu上面安装出错

在ubuntu上面执行:pip install itchatmp
出现了下面的错误:
`x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c build/temp.linux-x86_64-2.7/_openssl.c -o build/temp.linux-x86_64-2.7/build/temp.linux-x86_64-2.7/_openssl.o
build/temp.linux-x86_64-2.7/_openssl.c:434:30: fatal error: openssl/opensslv.h: No such file or directory
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1


Failed building wheel for cryptography`

使用被动回复,抛出‘TypeError'异常

使用被动回复接口时,抛出异常,比较奇怪的是有时出错,有时正常,是不是网络问题的锅?
代码如下:
@itchatmp.msg_register(itchatmp.content.LINK)
def linx_reply(msg):
if u'红包' in msg['Title']:
red_dict[msg['FromUserName']] = msg['Url']
#下面方法为向某网站api接口请求数据
conunt_left = connect_mtdhb.update_counts()
return u'系统可用红包点数为 ' + str(conunt_left) + ',请输入红包密令'
异常日志如下:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/tornado/web.py", line 1592, in _execute result = yield result
File "/usr/local/lib/python3.6/site-packages/tornado/gen.py", line 1133, in run value = future.result()
File "/usr/local/lib/python3.6/site-packages/tornado/gen.py", line 1141, in run yielded = self.gen.throw(*exc_info)
File "/usr/local/lib/python3.6/site-packages/itchatmp/components/register.py", line 236, in post (rawReply, rawReply.get('ToUserName', '')))
File "/usr/local/lib/python3.6/site-packages/tornado/gen.py", line 1133, in run value = future.result()
File "/usr/local/lib/python3.6/concurrent/futures/_base.py", line 425, in result return self.__get_result()
File "/usr/local/lib/python3.6/concurrent/futures/_base.py", line 384, in __get_result raise self._exception
File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run result = self.fn(*self.args, **self.kwargs)
TypeError: send() missing 1 required positional argument: 'toUserName'

Python3 多线程 更新token报错

更新token以后 会报错

#Wechat Auto Reply logic
@itchatmp.msg_register(itchatmp.content.TEXT)
def text_reply(msg):

    if(msg['Content'].isdigit() and len(msg['Content']) == 5):
        return addjob(msg['FromUserName'],msg['Content'])

        WrongCRN = [u'好像没有这个课号呢!课号一般是5位数。',u'难受!没这个课号!再试试其他的吧!',u'逗我呢?',u'你**在给我free style吗?']
        return random.choice(WrongCRN)


@itchatmp.access_token
def producer(accessToken=None):
    while(1):
        if hasUpdated():
            itchatmp.send(str(datetime.datetime.now()),'oO3tH0e3rt_j85k3ASkztTBM8Mec')
            print('1')
        else:
            sleep(1)
            continue


#MultiThread

###### main auto reply ######
replyThread = threading.Thread(target=itchatmp.run)
# prevent Main Thread to continue
replyThread.setDaemon(True)
# start as Daemon
replyThread.start()

###### producer #####
producer = threading.Thread(target=producer)
producer.setDaemon(True)
producer.start()

replyThread.join()
producer.join()

每次都是Update Token以后 第二个thread 会报错

root@chi-us-vu:~/courserader# cat server/py_core/out.log
itchatmp started! press Ctrl+C to exit.
1
1
1
1
1
1
1
1
1
1
1
Access token updated
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.5/dist-packages/itchatmp-0.0.17-py3.5.egg/itchatmp/controllers/mpapi/base/common.py", line 150, in __access_token
    r = fn(*args, **kwargs)
  File "./wechat.py", line 47, in producer
    itchatmp.send(str(datetime.datetime.now()),'oO3tH0e3rt_j85k3ASkztTBM8Mec')
  File "/usr/local/lib/python3.5/dist-packages/itchatmp-0.0.17-py3.5.egg/itchatmp/server.py", line 82, in send
    return self.wrapped.send(msg, toUserName, mediaId)
  File "/usr/local/lib/python3.5/dist-packages/itchatmp-0.0.17-py3.5.egg/itchatmp/controllers/wrapped.py", line 7, in send
    self.core, msg, toUserName, mediaId)
  File "/usr/local/lib/python3.5/dist-packages/itchatmp-0.0.17-py3.5.egg/itchatmp/controllers/common.py", line 23, in determine_wrapper
    return tokenFn(mpFn)(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/itchatmp-0.0.17-py3.5.egg/itchatmp/controllers/mpapi/base/common.py", line 145, in __access_token
    updateResult = self.update_access_token()
  File "/usr/local/lib/python3.5/dist-packages/itchatmp-0.0.17-py3.5.egg/itchatmp/controllers/mpapi/base/common.py", line 173, in update_access_token
    return self._tokenFunction()
  File "/usr/local/lib/python3.5/dist-packages/itchatmp-0.0.17-py3.5.egg/itchatmp/controllers/mpapi/base/common.py", line 68, in _update_access_token
    self.maintain_access_token(r)
  File "/usr/local/lib/python3.5/dist-packages/itchatmp-0.0.17-py3.5.egg/itchatmp/controllers/mpapi/base/common.py", line 84, in maintain_access_token
    t = threading.Thread(target=auto_maintain_thread,
NameError: name 'auto_maintain_thread' is not defined

处理超时时自动回复的代码在何处?如何配置?

Hi,
以如下代码为例:

@itchatmp.msg_register(itchatmp.content.TEXT)
def text_reply(msg):
    back = DoSomething()
    return back

如果DoSomething 执行超过5秒,我发现微信并不会返回服务器错误。 在log中看到了itchatmp好像是自动处理了这个超时的情况。 请问自动处理的代码在哪里,我是否可以更改自动回复的内容?
其实我主要想确定自动回复的判定是怎样的,是否是以超过5秒为判断标准?

发送视频设置 标题和简介 无法设置

upload里面设置title和introduction是无效的
additionalDict 这个参数如何在send的时候传入?

r = itchatmp.messages.upload(itchatmp.content.VIDEO, videoObj.out_video, {
'title': 'title test',
'introduction': 'introduction test'})
if r:
r = itchatmp.send('@vid@', fromUser, r['media_id'])
这样返回的视频是没有title和introduction的 media_id里面应该没有包含标题和简介信息
media_id title description应该在send里面传入

itchatmp.send 单纯文本的bug

我用itchatmp.send('hello',fromUser)一直无法发出
itchatmp.send("@txt@xxx",fromUser) 也无法发出
用了 itchatmp.customerservice.send(itchatmp.content.TEXT,“helloa”,{},fromUser)可以发出去
这两个应该是一样的东西 应该是additionalDict这个参数的问题

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.