title: Works with urrlib.request but doesn't work with requests
body: <h2>I am trying to send a request wtih post method to an API, my code looks like the following one:</h2>
  <pre><code>import urllib.request
  import json
  
  url         = &quot;https://api.cloudflareclient.com/v0a745/reg&quot;
  referrer    = &quot;e7b507ed-5256-4bfc-8f17-2652d3f0851f&quot;
  body        = {&quot;referrer&quot;: referrer}
  data        = json.dumps(body).encode('utf8')
  headers     = {'User-Agent': 'okhttp/3.12.1'}
  req         = urllib.request.Request(url, data, headers)
  response    = urllib.request.urlopen(req)
  status_code = response.getcode()
  print (status_code)
  </code></pre>
  <h2>Actually it works fine but i want to use &quot;requests&quot; library instead as it's more updated and more flexible with proxies with following code:</h2>
  <pre><code>import requests
  import json
  
  url         = &quot;https://api.cloudflareclient.com/v0a745/reg&quot;
  referrer    = &quot;e7b507ed-5256-4bfc-8f17-2652d3f0851f&quot;
  data        = {&quot;referrer&quot;: referrer}
  headers     = {'User-Agent': 'okhttp/3.12.1'}
  req         = requests.post(url, headers=headers, json=data)
  status_code = req.status_code
  print (status_code)
  </code></pre>
  <p>But it returns <strong>403 status code</strong>, how can i fix it ?</p>
  <p>Keep in mind that this API is open to everyone and you can just run the code with no worries.</p>
  <hr />
  <p><strong>EDIT-1</strong>: i have tried removing <code>json.dumps(body).encode('utf8')</code> or just <code>.encode('utf8')</code> from the second code by @tomasz-wojcik advice but i am still getting 403 while the first code still works!</p>
  <p><strong>EDIT-2</strong>: i tried requesting with postman that successfully made the request and returned <strong>200 status code</strong>. postman generated the following python code:</p>
  <pre><code>import requests
  
  url = &quot;https://api.cloudflareclient.com/v0a745/reg&quot;
  
  payload = &quot;{\&quot;referrer\&quot;: \&quot;e7b507ed-5256-4bfc-8f17-2652d3f0851f\&quot;}&quot;
  headers = {
    'Content-Type': 'application/x-www-form-urlencoded',
    'User-Agent': 'okhttp/3.12.1',
    'Host': 'api.cloudflareclient.com'
  }
  
  response = requests.request(&quot;POST&quot;, url, headers=headers, data=payload)
  
  status_code = response.status_code
  print (status_code)
  </code></pre>
  <p>If you run the code outside of postman, it still returns <strong>403 status code</strong>, i'm a litte confused, i am thinking that maybe &quot;requests&quot; library doesn't changing the user-agent in the second code.</p>
  <p><strong>EDIT-3</strong>: I have looked into it and found out that it works on python 2.7.16 but doesn't work on python 3.8.5!</p>
  <p><strong>EDIT-4</strong>: Some Developers are reporting that the second code works on python 3.6 too but the main thing is why it is working on other versions but not working on 3.8 or 3.7 ?</p>
  <h2>Python Versions that returned 403 status code(second code): 3.8.5 &amp; 3.7</h2>
  <h2>Python Versions that returned 200 status code(second code): 3.6 &amp; 2.7.16</h2>