Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

图文消息回复时图文个数一直在递增 #49

Closed
iblogc opened this issue May 14, 2015 · 14 comments
Closed

图文消息回复时图文个数一直在递增 #49

iblogc opened this issue May 14, 2015 · 14 comments

Comments

@iblogc
Copy link
Contributor

iblogc commented May 14, 2015

if isinstance(message, TextMessage):
            print u'文本消息'
            reply = ArticlesReply(message=message)
            reply.add_article({
                'title': '猫',
                'description': '描述文字……',
                'image': 'http://a.hiphotos.baidu.com/image/w%3D310/sign=595a29f639c79f3d8fe1e2318aa0cdbc/43a7d933c895d1433d2c882a71f082025aaf0764.jpg',
                'url': 'http://www.baidu.com'
            })
            return HttpResponse(reply, mimetype='application/javascript')

20150514160140435

@messense
Copy link
Member

稍后看下,谢谢反馈。

@messense messense added the bug label May 14, 2015
@messense
Copy link
Member

有解决方案的话欢迎提供思路/PR :-)

@zhangwen9229
Copy link

articles = [
{
'title': 'test',
'description': 'test',
'image': 'http://192.168.10.79:5000/static/pictures/6bbff4b0-f238-11e4-8cd5-40167e25126e.jpg',
'url': 'http://192.168.10.79:5000'
}, {
'title': 'tt22',
'description': 'tt2222',
'image': 'http://192.168.10.79:5000/static/pictures/6bbff4b0-f238-11e4-8cd5-40167e25126e.jpg',
'url': 'http://192.168.10.79:5000'
}
]
articles_reply = create_reply(articles, message=msg)
可以用这个方法
楼主的方法,我也遇到这种情况了,可是后来又好了,你重启服务端试试。

@iblogc
Copy link
Contributor Author

iblogc commented May 14, 2015

@zhangwen9229 用这个快速回复可避免这个问题

@zhangwen9229
Copy link

@korvin101 我上面提到的方法,是没问题的。 楼主用的快捷回复有问题。
reply = ArticlesReply(message=message)
reply.add_article({
'title': '猫',
'description': '描述文字……',
'image': 'http://a.hiphotos.baidu.com/image/w%3D310/sign=595a29f639c79f3d8fe1e2318aa0cdbc/43a7d933c895d1433d2c882a71f082025aaf0764.jpg',
'url': 'http://www.baidu.com'
})
return HttpResponse(reply, mimetype='application/javascript')

我昨天测试该方法的时候,就出现一次重复现象,后面,重启服务端后,就没问题了,我用的是flask

@messense
Copy link
Member

In [1]: from wechatpy.replies import ArticlesReply

In [2]: r = ArticlesReply()

In [3]: ar = {'title': 't', 'url': 'test'}

In [4]: r.add_article(ar)
> /Users/lls/Projects/wechatpy/wechatpy/replies.py(252)add_article()
    251         import ipdb; ipdb.set_trace()
--> 252         articles = self.articles
    253         articles.append(article)

ipdb> n
> /Users/lls/Projects/wechatpy/wechatpy/replies.py(253)add_article()
    252         articles = self.articles
--> 253         articles.append(article)
    254         self.articles = articles

ipdb> articles
[]
ipdb> id(articles)
4495189200
ipdb> id(self.articles)
4495189200
ipdb> n
> /Users/lls/Projects/wechatpy/wechatpy/replies.py(254)add_article()
    253         articles.append(article)
--> 254         self.articles = articles
    255

ipdb> articles
[{'url': 'test', 'title': 't'}]
ipdb> self.articles
[{'url': 'test', 'title': 't'}]
ipdb> n
> /Users/lls/Projects/wechatpy/wechatpy/fields.py(40)__set__()
     39         import ipdb; ipdb.set_trace()
---> 40         instance._data[self.attr_name] = value
     41

ipdb> instance
<wechatpy.replies.ArticlesReply object at 0x10c148f50>
ipdb> instance._data
{u'Articles': [{'url': 'test', 'title': 't'}], u'CreateTime': 1431592305}
ipdb> value
[{'url': 'test', 'title': 't'}]
ipdb> n
--Return--
None
> /Users/lls/Projects/wechatpy/wechatpy/fields.py(40)__set__()
     39         import ipdb; ipdb.set_trace()
---> 40         instance._data[self.attr_name] = value
     41

ipdb> instance
<wechatpy.replies.ArticlesReply object at 0x10c148f50>
ipdb> instance._data
{u'Articles': [{'url': 'test', 'title': 't'}], u'CreateTime': 1431592305}
ipdb> c

In [5]: r
Out[5]: <wechatpy.replies.ArticlesReply at 0x10c148f50>

In [6]: r._data
Out[6]: {u'Articles': [{'title': 't', 'url': 'test'}], u'CreateTime': 1431592305}

In [7]: r1 = ArticlesReply()

In [8]: r1._data
Out[8]: {u'CreateTime': 1431592428}

In [9]: r1.render()
Out[9]: u'<xml>\n<MsgType><![CDATA[news]]></MsgType>\n<ArticleCount>1</ArticleCount>\n        <Articles><item>\n            <Title><![CDATA[t]]></Title>\n            <Description><![CDATA[]]></Description>\n            <PicUrl><![CDATA[]]></PicUrl>\n            <Url><![CDATA[test]]></Url>\n            </item></Articles>\n<CreateTime>1431592428</CreateTime>\n<ToUserName><![CDATA[]]></ToUserName>\n<FromUserName><![CDATA[]]></FromUserName>\n</xml>'

In [10]: r1.articles
Out[10]: [{'title': 't', 'url': 'test'}]

In [11]: id(r1.articles)
Out[11]: 4495189200

In [12]: type(r1.articles)
Out[12]: list

In [13]: r1.articles == r.articles
Out[13]: True

In [14]: id(r1.articles) == id(r.articles)
Out[14]: True

大概定位到问题了。

@iblogc
Copy link
Contributor Author

iblogc commented May 14, 2015

👏好速度

@messense
Copy link
Member

@korvin101 试试:

pip install https://github.com/messense/wechatpy/archive/develop.zip

看看解决没有

@zhangwen9229
Copy link

@messense 我们这边是不是只要 pip install -U wechatpy 就可以了

@messense
Copy link
Member

@zhangwen9229 还没有发布到 PyPi,稍后发布新版本到 PyPi 就可以 pip install -U wechatpy 搞定了,暂时需要用上面的方法。

@iblogc
Copy link
Contributor Author

iblogc commented May 14, 2015

下面两种回复图文消息方式测试都正常了

from wechatpy.replies import ArticlesReply
from wechatpy.utils import ObjectDict

reply = ArticlesReply(message=message)
# simply use dict as article
reply.add_article({
    'title': 'test',
    'description': 'test',
    'image': 'image url',
    'url': 'url'
})
# or you can use ObjectDict
article = ObjectDict()
article.title = 'test'
article.description = 'test'
article.image = 'image url'
article.url = 'url'
reply.add_article(article)

@messense
Copy link
Member

@korvin101 Thanks,那我就发布一个新版本到 PyPi 大家方便安装升级。

@messense
Copy link
Member

@korvin101 @zhangwen9229 v0.8.6 已经发布到 PyPi。

https://pypi.python.org/pypi/wechatpy/0.8.6

@iblogc
Copy link
Contributor Author

iblogc commented May 14, 2015

已更新,没有发现问题:smile:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants