Python requests code snippet from Postman -


i trying check if email exists in website. using sample python code postman.

sample code works:

import requests  url = "https://registration.mercadolivre.com.br/registration/"  payload = "-----011000010111000001101001\r\ncontent-disposition: form-data; name=\"signup.email\"\r\n\r\ntest@hotmail.com\r\n-----011000010111000001101001\r\ncontent-disposition: form-data; name=\"signup.repemail\"\r\n\r\ntest@hotmail.com\r\n-----011000010111000001101001\r\ncontent-disposition: form-data; name=\"signup.newsletter\"\r\n\r\ntrue\r\n-----011000010111000001101001\r\ncontent-disposition: form-data; name=\"source\"\r\n\r\nmercadolibre\r\n-----011000010111000001101001--" headers = { 'content-type': "multipart/form-data; boundary=---011000010111000001101001", 'cache-control': "no-cache", 'postman-token': "179cabe2-dd22-490e-8fbd-15bf2977feb5" }  response = requests.request("post", url, data=payload, headers=headers)  print(response.text) 

i not sure why postman encoding payload in string. when try passing dictionary not work anymore

code not work:

import requests  url = "https://registration.mercadolivre.com.br/registration/"  payload = { 'signup.email': 'test@hotmail.com',  'signup.repemail': 'test@hotmail.com',  'signup.newsletter': 'true',  'source': 'mercadolibre' } headers = { 'content-type': "multipart/form-data; boundary=---011000010111000001101001", 'cache-control': "no-cache", 'postman-token': "22a12fa5-5f68-685c-124d-db0ef6eb334c" }  response = requests.request("post", url, data=payload, headers=headers)  print(response.text) 

i wondering why can't pass json or dictionary.

your json version works fine

import requests  url = "https://registration.mercadolivre.com.br/registration/"  payload = { 'signup.email': 'test@hotmail.com',  'signup.repemail': 'test@hotmail.com',  'signup.newsletter': 'true',  'source': 'mercadolibre' } headers = { 'content-type': "multipart/form-data; boundary=---011000010111000001101001", 'cache-control': "no-cache", 'postman-token': "22a12fa5-5f68-685c-124d-db0ef6eb334c" }  response = requests.request("post", url, data=payload, headers=headers)  print(response.text) 

output

> python payload.py <!doctype html> <!--[if lt ie 7]> <html lang="es-ar" class="no-js lt-ie10 lt-ie9 lt-ie8 lt-ie7 ie6"> <![endif]--><!--[if ie 7]> <html lang="es-ar" class="no-js lt-ie10 lt-ie9 lt-ie8 ie7"> <![endif]--><!--[if ie 8]> <html lang="es-ar" class="no-js lt-ie10 lt-ie9 ie8"> <![endif]--><!--[if ie 9]> <html lang="es-ar" class="no-js lt-ie10 ie9"> <![endif]--><!--[if (gt ie 9)|!(ie)]> <!--> <html lang="es-ar" class="no-js"> <!--<![endif]--> <head><meta content="text/html; charset=utf-8"/><title>mercadolivre - ocorreu um erro</title><link rel=stylesheet href="/css/null/7.0.5/errorpage.css"/><!--[if lt ie 7 ]><script src="http://www.mercadolibre.com/org-img/pcorner/js/dd_belatedpng.min.js"></script><script> dd_belatedpng.fix('img, .ico, .png24fix, .ch-expando-trigger'); //fix <img> or .ico background-images </script><![endif]--><link rel="shortcut icon" href="//http2.mlstatic.com/ui/navigation/1.5.9/mercadolibre/favicon.ico"/></head><body data-country=ar><div class=errorpage500><p class=ups>ops!</p><div class=errormessage><h2>ocorreu um erro</h2><p>por favor, tente mais tarde.</p></div></div></body></html> <!--     stats     generate time       : 36 ms     render time         : 1 ms     compress time       : 1 ms     total time          : 38 ms     hostname            : i-3647d238-10.17.67.12 --> 

i guess problem may version mine python version 3.4.2 requests 2.11.1


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -