littlecodersh/itchatmp

功能与意见反馈,报bug可以另开issue

littlecodersh opened this issue · 15 comments

都可以在这里交流,我会及时回复的~
也欢迎加入QQ群讨论:438747166

python3 main.py 报错

File "main.py", line 8, in <module>
    r = itchatmp.send('greeting from itchatmp!', userId)
  File "/usr/local/lib/python3.6/site-packages/itchatmp/controllers/wrapped.py", line 9, in send
    msg, toUserName, mediaId)
  File "/usr/local/lib/python3.6/site-packages/itchatmp/controllers/common.py", line 19, in determine_wrapper
    return mpFn(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/itchatmp/controllers/mpapi/mp/wrapped.py", line 68, in send
    r = cssend(msgType, mediaId, additionalDict=msg, toUserId=toUserId)
  File "/usr/local/lib/python3.6/site-packages/itchatmp/controllers/mpapi/base/common.py", line 152, in __access_token
    r = fn(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/itchatmp/controllers/mpapi/mp/customerservice.py", line 99, in send
    msgDict = __form_send_dict(msgType, mediaId, additionalDict)
  File "/usr/local/lib/python3.6/site-packages/itchatmp/controllers/mpapi/mp/customerservice.py", line 137, in __form_send_dict
    MUSIC: {'music': additionalDict['music'], 'msgtype': 'music'},
KeyError: 'music

@lwj714003758 升级新版本试试。

没有认证过的个人公众订阅号 中如何直接对用户进行回复啊. 我看了微信公众号的API貌似是不允许的, 但是在网页版中可以直接这么做. 我想着有没有可能itchatmp也有这个功能呢

@littlecodersh pip上的还是0.0.16版, 跑text_reply示例在template.format(**replyDict)会报错, 因为'Content' key没有正确被设置

@littlecodersh
更新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

使用NATAPP二级域名配套环境的时候,出现这样的错误信息,请问如何解决?

E:\python\py3\p\itchat\mpxl>python main.py
itchatmp started! press Ctrl+C to exit.
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\itchatmp\controllers\envtest.py", line 33, in env_test
s.bind(('127.0.0.1', port))
OSError: [WinError 10013] 以一种访问权限不允许的方式做了一个访问套接字的尝试。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "main.py", line 8, in
itchatmp.run()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\itchatmp\components\register.py", line 265, in run
env_test(port)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\itchatmp\controllers\envtest.py", line 37, in env_test
raise EnvironmentError(PORT_WARNING)
itchatmp.exceptions.EnvironmentError: port 80 is in use.

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

C:\Users\山海>pip install itchatmp
Collecting itchatmp
Using cached itchatmp-0.0.17-py2.py3-none-any.whl
Collecting tornado (from itchatmp)
Using cached tornado-4.5.2-cp36-cp36m-win_amd64.whl
Collecting futures (from itchatmp)
Using cached futures-3.1.1.tar.gz
Exception:
Traceback (most recent call last):
File "C:\Users\山海\AppData\Local\Programs\Python\Python36\lib\site-packages\pip-9.0.1-py3.6.egg\pip\compat_init_.py", line 73, in console_to_str
return s.decode(sys.stdout.encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xba in position 11: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\山海\AppData\Local\Programs\Python\Python36\lib\site-packages\pip-9.0.1-py3.6.egg\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "C:\Users\山海\AppData\Local\Programs\Python\Python36\lib\site-packages\pip-9.0.1-py3.6.egg\pip\commands\install.py", line 324, in run
requirement_set.prepare_files(finder)
File "C:\Users\山海\AppData\Local\Programs\Python\Python36\lib\site-packages\pip-9.0.1-py3.6.egg\pip\req\req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "C:\Users\山海\AppData\Local\Programs\Python\Python36\lib\site-packages\pip-9.0.1-py3.6.egg\pip\req\req_set.py", line 634, in prepare_file
abstract_dist.prep_for_dist()
File "C:\Users\山海\AppData\Local\Programs\Python\Python36\lib\site-packages\pip-9.0.1-py3.6.egg\pip\req\req_set.py", line 129, in prep_for_dist
self.req_to_install.run_egg_info()
File "C:\Users\山海\AppData\Local\Programs\Python\Python36\lib\site-packages\pip-9.0.1-py3.6.egg\pip\req\req_install.py", line 439, in run_egg_info
command_desc='python setup.py egg_info')
File "C:\Users\山海\AppData\Local\Programs\Python\Python36\lib\site-packages\pip-9.0.1-py3.6.egg\pip\utils_init
.py", line 676, in call_subprocess
line = console_to_str(proc.stdout.readline())
File "C:\Users\山海\AppData\Local\Programs\Python\Python36\lib\site-packages\pip-9.0.1-py3.6.egg\pip\compat_init_.py", line 75, in console_to_str
return s.decode('utf_8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xba in position 11: invalid start byte

那个请问,这个是怎么回事。

ubuntu 16.04
from tornado.wsgi import WSGIAdapter
ImportError: cannot import name 'WSGIAdapter'

windows10
from tornado.wsgi import WSGIAdapter
ImportError: cannot import name 'WSGIAdapter' from 'tornado.wsgi' (E:\PythonCodes\venv\lib\site-packages\tornado\wsgi.py)
问题解决。
tornado 6.0.1版本已经删除WSGIAdapter

hswxy commented

运行以下代码后报此错误:
EnvironmentError: port 80 is in use.

`import itchatmp

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

@itchatmp.msg_register(itchatmp.content.TEXT)
def text_reply(msg):
return msg['Content']

itchatmp.run()

`

80端口确实被其他应用站用了,我想请教的是itchatmp运行时如何修改端口号,不使用80。

请问我要获取某个微信公众号向我的微信发的消息,要怎么获取呢。

请问作者还在更新吗?py3.0好像总有报错,另外请问怎样才能获得菜单click的动作哪?

现在不更新了吗,大多数微信不支持网页版微信 登入怎么办

spun64 commented

@littlecodersh 更新токен以后 会报错 求帮忙看看原因谢谢

#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

当消息处理耗时较长时(>5s),会报错,当处理时长较短时,均可以正常返回
Uncaught exception POST /?signature=f5c452358688a865c6eaf73645247900772c9f35&timestamp=1728309084&nonce=1895343502&openid=ofgWrxE9o7XF-Be8BpsQpp0YFgXI (175.24.212.185) HTTPServerRequest(protocol='http', host='182.92.177.62', method='POST', uri='/?signature=f5c452358688a865c6eaf73645247900772c9f35&timestamp=1728309084&nonce=1895343502&openid=ofgWrxE9o7XF-Be8BpsQpp0YFgXI', version='HTTP/1.1', remote_ip='175.24.212.185', headers={'User-Agent': 'Mozilla/4.0', 'Accept': '*/*', 'Host': '182.92.177.62', 'Pragma': 'no-cache', 'Content-Length': '286', 'Content-Type': 'text/xml'}) Traceback (most recent call last): File "/root/anaconda3/envs/wechatmp_py3.7/lib/python3.8/site-packages/tornado/web.py", line 1512, in _execute result = yield result File "/root/anaconda3/envs/wechatmp_py3.7/lib/python3.8/site-packages/tornado/gen.py", line 1055, in run value = future.result() File "/root/anaconda3/envs/wechatmp_py3.7/lib/python3.8/site-packages/tornado/concurrent.py", line 238, in result raise_exc_info(self._exc_info) File "<string>", line 4, in raise_exc_info File "/root/anaconda3/envs/wechatmp_py3.7/lib/python3.8/site-packages/tornado/gen.py", line 1063, in run yielded = self.gen.throw(*exc_info) File "/root/anaconda3/envs/wechatmp_py3.7/lib/python3.8/site-packages/itchatmp/components/register.py", line 235, in post r = yield threadPool.submit(core.send, File "/root/anaconda3/envs/wechatmp_py3.7/lib/python3.8/site-packages/tornado/gen.py", line 1055, in run value = future.result() File "/root/anaconda3/envs/wechatmp_py3.7/lib/python3.8/concurrent/futures/_base.py", line 437, in result return self.__get_result() File "/root/anaconda3/envs/wechatmp_py3.7/lib/python3.8/concurrent/futures/_base.py", line 389, in __get_result raise self._exception File "/root/anaconda3/envs/wechatmp_py3.7/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) TypeError: send() missing 1 required positional argument: 'toUserName'