短信使用python的字符@显示为倒置?

问题描述:

我正在使用SMS网关发送使用python脚本的SMS消息。在短信中,我会将URL中的用户电子邮件作为get参数发送。但是,无论何时我使用电子邮件地址发送短信,它都会显示@为“倒置?”。符号。请参阅下面的代码:短信使用python的字符@显示为倒置?

message = u'Click url http://services.indg.in/[email protected] to activate account' 

values = {'username' : username, 
'password' : password, 
'smsservicetype' : smsservicetype, 
'content' : message, 
'mobileno' : numbers, 
'senderid' : senderid 
} 

url = 'gateway url comes here' 

postdata = urllib.urlencode(values) 
req = urllib2.Request(url, postdata) 
req.add_header("Content-Type","application/x-www-form-urlencoded"); 
req.add_header("User-Agent","Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)"); 

try: 
    response = urllib2.urlopen(req) 
    print response 
    response_url = response.geturl() 
    if response_url==url: 
     print 'SMS sent!' 
except urllib2.URLError, e: 
    print 'Send failed!' 
    print e.reason 

enter image description here

+0

你用卷曲试过了吗?只是为了测试.. – brunsgaard 2014-09-22 11:18:42

这似乎是一个编码的问题

尝试:

Content-type: application/x-www-form-urlencoded; charset=utf-8 

也把

# -*- coding: utf-8 -*- 

在脚本的顶部。

否则,请阅读您网关的文档,找出它们支持/期望的字符集。