Requests Module Python
Question: I have an application running with PHP and CURL. My idea is to move the
application to Python-Django-Requests. I have been unable to work, I hope you
can give me a hand please. The application works as follows: Collect: a
number, a message and through an API sends an SMS.

PHP code. <http://pastebin.com/PqpBgstD>

    
    
    import requests
    import cookielib
    posdata = "p_num_text=00513015924048&smstemplate=&message=message_sending&txtcount=8
               +char+%3A+1+Sms&hiddcount=152"
    jar = cookielib.CookieJar()
    user = 'xxx'
    pass = 'xxx'
    values = {'app': 'page', 'inc': 'login', 'op': 'auth_login',
               'username': user, 'password': pass} # data login
    r = requests.post(url, data=values, cookies=jar) # Login
    values = {'app': 'menu', 'inc': 'send_sms',
               'op': 'sendsmstopv_yes'}# values ​​to enter to send the sms 
    r = requests.post(url, data=values, params=posdata, cookies=jar)# enter the area sms
    print r.content
    

How I can pass the code in CURL to Requests?

Does the above code is fine?


Answer: Your code will not work, I've attached the corrected code below, note that you
don't need to use `cookielib` as `Requests`'s `cookie` will generate a
`CookieJar` object.

    
    
    import requests
    
    url = "http://dominio.com/subdominio/index.php"
    
    username = 'xxx'
    password = 'xxx'
    
    payload = {
        'app': 'page',
        'inc': 'login',
        'op': 'auth_login',
        'username': username,
        'password': password}
    
    r = requests.post(url, data=payload)  # Login
    
    cSMS = "Sms"
    
    payload = {
        'p_num_text': '00513015924048',
        'smstemplate': '',
        'message': 'message_sending',
        'txtcount': '8',
        'char': cSMS,   # your php code seems to be off for this one, double check it
        'hiddcount': '153'}
    
    url = "http://dominio.com/subdominio/index.php?app=menu&inc=send_sms&op=sendsmstopv_yes"
    
    r = requests.post(url, data=payload, cookies=r.cookies)  # enter the area sms
    
    print r.text
    

