gat*_*ina 5 python sockets sms mms python-2.7
我正在使用下面的代码尝试使用python-messaging https://github.com/pmarti/python-messaging/blob/master/doc/tutorial/mms.rst发送彩信.虽然连接似乎顺利但我从mmsc获得以下响应:
PROXY RESPONSE HTTP/1.0 200 OK
content-type: application/vnd.wap.mms-message
content-length: 59
Connection: close
Date: Sat, 05 Jan 2019 16:36:44 GMT
Server: Mavenir Web Application Server
???1234?????,?Failed to handle HTTP request in Mm1Server
Run Code Online (Sandbox Code Playgroud)
有没有人知道问题可能是什么以及如何解决?这是我的代码:
from messaging.mms.message import MMSMessage, MMSMessagePage
mms = MMSMessage()
mms.headers['To'] = '+212XXXXXXX/TYPE=PLMN'
mms.headers['Message-Type'] = 'm-send-req'
mms.headers['Subject'] = 'Test python-messaging.mms'
slide1 = MMSMessagePage()
slide1.add_image('/home/richard/screensaver/TolleConscQte.jpg')
slide1.add_text('This first slide, is a step towards enlightenment.')
slide2 = MMSMessagePage()
slide2.set_duration(4500)
slide2.add_image('/home/richard/screensaver/TollePastALL.jpg', 1500)
slide2.add_text('This second slide is a second step towards enlightenment.', 500, 3500)
mms.add_page(slide1)
mms.add_page(slide2)
payload = mms.encode()
## sending the MMS
from cStringIO import StringIO
import socket
gw_host, gw_port = "10.188.239.143", 80 #ting
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((gw_host, gw_port))
s.send("POST %s HTTP/1.0\r\n" % "http://wholesale.mmsmvno.com/mms/wapenc")
s.send("Content-Type: application/vnd.wap.mms-message\r\n")
s.send("Content-Length: %d\r\n\r\n" % len(payload))
s.sendall(payload)
buf = StringIO()
while True:
data = s.recv(4096)
if not data:
break
buf.write(data)
s.close()
data = buf.getvalue()
buf.close()
print "PROXY RESPONSE", data
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的错误。该错误与编码的 MMS PDU 相关,而不是 http 请求。我可以通过显式设置 From 标头来使其工作:
mms.headers['From'] = ''
Run Code Online (Sandbox Code Playgroud)
这将导致 python-messaging 库将 From 标头设置为Insert-address-token.
我使用这个测试文件进行调试(只需更改“收件人”电话号码)。
使用普通的 http 客户端也可以。只需确保您正在设置Content-Type和Content-Length。