python-messaging Failed to handle HTTP request

2024/10/12 13:19:20

I am using the code below to try to send an MMS message with python-messaging https://github.com/pmarti/python-messaging/blob/master/doc/tutorial/mms.rst Although the connection seems to go smoothly I get the following response from the 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

Does, anyone have an idea on what the problem might be and how I can fix it? Here is my code:

from messaging.mms.message import MMSMessage, MMSMessagePagemms = 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 MMSfrom cStringIO import StringIO
import socketgw_host, gw_port = "10.188.239.143", 80 #tings = 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:breakbuf.write(data)s.close()
data = buf.getvalue()
buf.close()print "PROXY RESPONSE", data
Answer

I ran into this same error. The error is with the encoded MMS PDU, not the http request. I was able to get this to work by explicitly setting the From header:

mms.headers['From'] = ''

This will cause the python-messaging library to set the From header to Insert-address-token.

I used this test file for debugging (just change the To phone number).

Its also fine to use a normal http client. Just make sure you are setting Content-Type and Content-Length.

https://en.xdnf.cn/q/69646.html

Related Q&A

Plotting confidence and prediction intervals with repeated entries

I have a correlation plot for two variables, the predictor variable (temperature) on the x-axis, and the response variable (density) on the y-axis. My best fit least squares regression line is a 2nd or…

Saving and Loading of dataframe to csv results in Unnamed columns

prob in the title. exaple:x=[(a,a,c) for i in range(5)] df = DataFrame(x,columns=[col1,col2,col3]) df.to_csv(test.csv) df1 = read_csv(test.csv)Unnamed: 0 col1 col2 col3 0 0 a a c 1 …

Python: print specific character from string

How do I print a specific character from a string in Python? I am still learning and now trying to make a hangman like program. The idea is that the user enters one character, and if it is in the word…

Python AttributeError: module string has no attribute maketrans

I am receiving the below error when trying to run a command in Python 3.5.2 shell:Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32 Type "copyrig…

How to add attribute to class in python

I have: class A:a=1b=2I want to make as setattr(A,c)then all objects that I create it from class A has c attribute. i did not want to use inheritance

Number of occurrence of pair of value in dataframe

I have dataframe with following columns:Name, Surname, dateOfBirth, city, countryI am interested to find what is most common combination of name and surname and how much it occurs as well. Would be nic…

how do i dump a single sqlite3 table in python?

I would like to dump only one table but by the looks of it, there is no parameter for this. I found this example of the dump but it is for all the tables in the DB: # Convert file existing_db.db to SQL…

Django automatically create primary keys for existing database tables

I have an existing database that Im trying to access with Django. I used python manage.py inspectdb to create the models for the database. Currently Im able to import the models into the python shell h…

matplotlib.pyplot scatterplot legend from color dictionary

Im trying to make a legend with my D_id_color dictionary for my scatterplot. How can I create a legend based on these values with the actual color? #!/usr/bin/python import matplotlib.pyplot as plt f…

Numpy Array Set Difference [duplicate]

This question already has answers here:Find the set difference between two large arrays (matrices) in Python(3 answers)Closed 7 years ago.I have two numpy arrays that have overlapping rows:import numpy…