title: Exception "A JSONObject text must begin with '{' at character 0 of" when posting data using request()
body: <p>I am planning to send request to server with the following code. I have spent more than 1 day to resolve this but without any progress. And please forgive me I have to hide the real URL address becuase of Company Security Policy.</p>
  
  <pre><code>import requests
  
  get_ci = requests.session()
  
  get_ci_url = 'https://this_is_a_fake_URL_to_paste_in_stackoverflow.JSON'
  get_ci_param_dict = {"Username": "fake","Password": "fakefakefake","CIType": "system","CIID": "sampleid","CIName": "","AttrFilter": "","SubObjFilter": ""}
  get_ci_param_str = str(get_ci_param_dict)
  
  print(get_ci_param_dict)
  print(get_ci_param_str)
  
  get_ci_result = get_ci.request('POST', url=get_ci_url, params=get_ci_param_str, verify=False)
  
  print(get_ci_result.status_code)
  print(get_ci_result.text)
  </code></pre>
  
  <p>And what I get in the Run result is,</p>
  
  <pre><code>C:\Python34\python.exe C:/Users/this/is/the/fake/path/Test_02.py
  {'CIID': 'sampleid', 'CIType': 'system', 'AttrFilter': '', 'Password': 'fake', 'CIName': '', 'Username': 'fake', 'SubObjFilter': ''}
  {'CIID': 'sampleid', 'CIType': 'system', 'AttrFilter': '', 'Password': 'fake', 'CIName': '', 'Username': 'fake', 'SubObjFilter': ''}
  C:\Python34\lib\requests\packages\urllib3\connectionpool.py:843: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
    InsecureRequestWarning)
  500
  &lt;ns1:XMLFault xmlns:ns1="http://cxf.apache.org/bindings/xformat"&gt;&lt;ns1:faultstring xmlns:ns1="http://cxf.apache.org/bindings/xformat"&gt;*org.codehaus.jettison.json.JSONException: A JSONObject text must begin with '{' at character 0 of* &lt;/ns1:faultstring&gt;&lt;/ns1:XMLFault&gt;
  
  Process finished with exit code 0
  </code></pre>
  
  <p>More tips,</p>
  
  <ol>
  <li><p>I have contact the Server Code Developer - They only need is a
  string in a JSON format sent in a "Parameter" way. Which means it
  is correct to use <code>params</code> in <code>request()</code>.</p></li>
  <li><p>I have tried with <code>dumps.json(get_ci_param_dict)</code> => The same result.</p></li>
  <li><p>It has returned the 200 code when I only request the server's root,
      which proves me the url is ok.</p></li>
  </ol>
  
  <hr>
  
  <p>Additional Logs when update the <code>params</code> to <code>data</code>.</p>
  
  <pre><code>C:\Python34\lib\requests\packages\urllib3\connectionpool.py:843: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
    InsecureRequestWarning)
  500
  &lt;html&gt;&lt;head&gt;&lt;title&gt;Apache Tomcat/7.0.61 - Error report&lt;/title&gt;&lt;style&gt;&lt;!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--&gt;&lt;/style&gt; &lt;/head&gt;&lt;body&gt;&lt;h1&gt;HTTP Status 500 - 1&lt;/h1&gt;&lt;HR size="1" noshade="noshade"&gt;&lt;p&gt;&lt;b&gt;type&lt;/b&gt; Exception report&lt;/p&gt;&lt;p&gt;&lt;b&gt;message&lt;/b&gt; &lt;u&gt;1&lt;/u&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;description&lt;/b&gt; &lt;u&gt;The server encountered an internal error that prevented it from fulfilling this request.&lt;/u&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;exception&lt;/b&gt; &lt;pre&gt;java.lang.ArrayIndexOutOfBoundsException: 1
      com.fake.security.XSSHttpReuquestWrapper.GeneralParameters(XSSHttpReuquestWrapper.java:158)
      com.fake.security.XSSHttpReuquestWrapper.checkParameter(XSSHttpReuquestWrapper.java:101)
      com.fake.security.XSSHttpReuquestWrapper.validateParameter(XSSHttpReuquestWrapper.java:142)
      com.fake.security.XSSSecurityFilter.doFilter(XSSSecurityFilter.java:35)
      com.fake.webservice.interceptor.GetContextFilter.doFilter(GetContextFilter.java:24)
      org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
      org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
  &lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;note&lt;/b&gt; &lt;u&gt;The full stack trace of the root cause is available in the Apache Tomcat/7.0.61 logs.&lt;/u&gt;&lt;/p&gt;&lt;HR size="1" noshade="noshade"&gt;&lt;h3&gt;Apache Tomcat/7.0.61&lt;/h3&gt;&lt;/body&gt;&lt;/html&gt;
  
  Process finished with exit code 0
  </code></pre>
  
  <hr>
  
  <p>FINAL SOLUTION FOR THIS QUESTION</p>
  
  <p>@e4c5 your suggestion is helpful to figure out the final solution. The <code>param</code> should be sent to server via <code>data</code>, as the <code>data</code> should be sent out as dict or byte as defined in the offical document, so need use <code>param</code> as the dict key to send. Please see the code as below,</p>
  
  <pre><code>import requests
  import json
  
  
  get_ci_url = 'https://sample.fake.com:0000/sample/fake/fakeagain.JSON'
  get_ci_param_dict = {"Username": "fake","Password": "fakefake".......}
  get_ci_param_json = json.dumps(get_ci_param_dict)
  
  params = {'param': get_ci_param_json}
  
  get_ci_result = requests.request('POST', url=get_ci_url, data=params, verify=False)
  
  print(get_ci_result.status_code)
  print(get_ci_result.text)
  </code></pre>
  
  <p>ROOT CAUSE:<code>param</code> should be sent via <code>data</code> parameter. Official Document has clearly state that => :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:<code>Request</code>.</p>
  
  <p>Thanks My colleauge - Mr.J and @e4c5's great help.</p>