Sending long JSON via POST Python
<p>I know this seems fundamental, but how do we do it? For example,</p>

<pre><code>import urllib2
import ssl
import requests
import json

SetProxy={'https':'https://sample.sample.com'}
proxy = urllib2.ProxyHandler(SetProxy)
url="https://something.com/getsomething"
opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)
payload = {
  "uaaURL": "https://com-example.something.com",
  "sampleID": "admin",
  "sampleSecret": "password",
  "sampleID2": "example-sample-el",
  "sampleSecret2": "ssenjsoemal/+11=",
  "username": "test",
  "someAttributes": {
    "Groups": [
      "example_com-abc"
    ],
    "attribute": [
      "value1"
    ]
  }
}

req = urllib2.Request(url)
req.add_header('Content-Type','application/json')
response = urllib2.urlopen(req, json=json.dumps(payload))
</code></pre>

<p>The above runs and gives me a 400 which means my JSON is bad. I was not able to find a post that sent large JSON data via a post request. Any advice? Thanks! </p>

<p>try to use below :</p>

<pre><code>import json

import urllib2

import ssl

import requests

SetProxy={'https':'https://sample.sample.com'}

proxy = urllib2.ProxyHandler(SetProxy)

url='https://something.com/getsomething'

opener = urllib2.build_opener(proxy)

urllib2.install_opener(opener)

data = {
  'uaaURL' : 'https://com-example.something.com',
  'sampleID': 'admin',
  'sampleSecret': 'password',
  'sampleID2': 'example-sample-el',
  'sampleSecret2': 'ssenjsoemal/+11=',
  'username': 'test',
  'someAttributes': {
    'Groups': ['example_com-abc' ],
    'attribute': [ 'value1' ]
  }

req = urllib2.Request('https://something.com/getsomething')

req.add_header('Content-Type', 'application/json')

response = urllib2.urlopen(req, json.dumps(data))
</code></pre>

python json