2016-11-08 11 views
0

メールがウェブサイトに既に存在するかどうかを確認しようとしています。現在、PostmanのサンプルPythonコードを使用しています。作品PythonがPostmanからコードスニペットを要求します

サンプルコード:

import requests 

url = "https://registration.mercadolivre.com.br/registration/" 

payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"signUp.email\"\r\n\r\[email protected]\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"signUp.repEmail\"\r\n\r\[email protected]\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) 

私はポストマンは、その文字列内のペイロードを符号化された理由はわかりません。私はJSONまたは辞書を渡すことができない理由

import requests 

url = "https://registration.mercadolivre.com.br/registration/" 

payload = { 'signUp.email': '[email protected]', 
'signUp.repEmail': '[email protected]', 
'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) 

が、私は疑問に思って:私は辞書を渡すしようとすると、それは動作しませんもう

コードは動作しません。

答えて

0

あなたのJSONのバージョンが正常に動作します

import requests 

url = "https://registration.mercadolivre.com.br/registration/" 

payload = { 'signUp.email': '[email protected]', 
'signUp.repEmail': '[email protected]', 
'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) 

出力

> 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 any <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 
--> 

私はあなたのバージョン鉱山Pythonのバージョンでも問題を推測するには、2.11.1である3.4.2 リクエストです

+0

実際に出力が異なるため、Jsonのバージョンは動作しません。それは "MercadoLivre - Ocorreu um erro"と書かれています。郵便配達員が提案した方法を使用すると、結果は電子メールがすでに使用中であるというメッセージと異なります。 – Legos

関連する問題