title: Request post method doesn't return valid response
body: <p>I am trying to work on a website that has simple captcha. Here's the <a href="https://eservices.moj.gov.kw/searchPages/searchCases.jsp" rel="nofollow noreferrer">link</a>.</p>
  <p><strong>Steps:</strong></p>
  <p>One is supposed to type a case number e.g. <code>200078510</code>, then type the numbers in the captcha, then click on <code>Search</code> button.</p>
  <p><strong>Progress:</strong></p>
  <p>I could solve the part of the captcha, but when trying to use the <code>POST</code> method in <code>requests</code> library, I didn't get a valid response. I got this string <code>حدث خطأ ما </code>, which means that <code>Something went wrong</code>. A successful response would have included the case number in the response e.g. <code>200078510</code>.</p>
  <p><strong>Question:</strong></p>
  <p>90% of the time myCaptcha is correct so the problem, I think, is with the POST request. Can anyone see what is wrong with my POST request?</p>
  <p>I provide a working VBA example at the end, as additional info, in case that helps.</p>
  <hr />
  <p>Here's the code that I could do till now:</p>
  <pre><code>import requests
  import cv2
  import numpy as np
  import pytesseract
  from PIL import Image
  
  sNumber = 'Number.png'
  sTemp = 'Temp.png'
  pytesseract.pytesseract.tesseract_cmd=r'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
  
  def getCaptcha():
      response = requests.get(&quot;https://eservices.moj.gov.kw/captcha/imgCaptcha.jsp&quot;)
      with open(sNumber, &quot;wb&quot;) as f:
          f.write(response.content)
          f.close()
      img = cv2.imread(sNumber)
      lower = np.array([0, 0, 0])
      upper = np.array([46, 46, 255])
      thresh = cv2.inRange(img, lower, upper)
      thresh = 255 - thresh
      cv2.imwrite(sTemp, thresh)   
      img=Image.open(sTemp)
      text=pytesseract.image_to_string(img, lang='eng',config='--psm 10 --oem 3 -c tessedit_char_whitelist=0123456789')
      return text
  
  myCaptcha = getCaptcha()
  print(myCaptcha)
  
  payload = {'txtCaseNo': '200078510', 'txtCaptcha2': myCaptcha, 'searchType': '0'}
  r = requests.post(&quot;https://eservices.moj.gov.kw/viewResults/validateCase.jsp&quot;, data=payload)
  print(r.url)
  print(r.text)
  </code></pre>
  <p>I even tried using headers like that and the same problem</p>
  <pre><code>headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36',
            'Content-Type':'application/x-www-form-urlencoded'}
  
  payload = {'txtCaseNo': '200078510', 'txtCaptcha2': myCaptcha, 'searchType': '0'}
  r = requests.post(&quot;https://eservices.moj.gov.kw/viewResults/validateCase.jsp&quot;,headers = headers, data=payload)
  </code></pre>
  <p>Simply I need to be able to use the POST method of the requests package so as to be able to send the suitable arguments and then navigate to multiple sections that are related to the searched number.</p>
  <hr />
  <h3>Supplementary Information (Working example reference in VBA):</h3>
  <p>I have a working code in VBA for the entire process. The code navigates to a URL and enter a number and enter the numbers on captcha. Here's the code:</p>
  <pre><code>Public vCaptcha
  
  Sub Test()
      Dim wsIndex As Worksheet, wsData As Worksheet, http As New XMLHTTP60, html As New HTMLDocument, htmlData As New HTMLDocument, postCasePane As Object, oTables As Object, postTable As Object, postWrongSec As Object, strArg As String, xTemp As String, sTemp As String, r As Long, lr As Long, i As Long, ii As Long, vMAX As Long, cnt As Long
      Set wsIndex = ThisWorkbook.Worksheets(&quot;Index&quot;)
      Set wsData = ThisWorkbook.Worksheets(&quot;Data&quot;)
      wsData.Range(&quot;A1&quot;).CurrentRegion.Offset(1).ClearContents
      For r = 2 To wsIndex.Cells(Rows.Count, 1).End(xlUp).Row
          If r Mod 10 = 0 Then ThisWorkbook.Save
          lr = wsData.Cells(Rows.Count, 1).End(xlUp).Row + 1
          If wsIndex.Cells(r, 1).Value = &quot;&quot; Then GoTo Skipper
  sPoint:
          Application.StatusBar = &quot;Case Number: &quot; &amp; wsIndex.Cells(r, 1).Value &amp; &quot; ------- Row &quot; &amp; r
          DecryptCaptcha
          strArg = &quot;txtCaseNo=&quot; &amp; wsIndex.Cells(r, 1).Value &amp; &quot;&amp;txtCaptcha2=&quot; &amp; vCaptcha &amp; &quot;&amp;searchType=0&quot;
          With http
              .Open &quot;POST&quot;, &quot;https://eservices.moj.gov.kw/viewResults/validateCase.jsp&quot;, False
              .setRequestHeader &quot;Content-type&quot;, &quot;application/x-www-form-urlencoded&quot;
              .send strArg
              html.body.innerHTML = .responseText
              Set postWrongSec = html.querySelector(&quot;span[lang='AR-KW']&quot;)
              If Not postWrongSec Is Nothing Then
                  If postWrongSec.innerText = &quot;ÚÝæÇ: ÑãÒ ÇáÍãÇíÉ ÛíÑ ÕÍíÍ !!!&quot; Then
                      cnt = cnt + 1
                      Debug.Print &quot;Wrong Captcha &quot; &amp; cnt: GoTo sPoint
                  End If
              End If
              Set postCasePane = html.querySelector(&quot;#caseViewPane span h4&quot;)
              If postCasePane Is Nothing Then wsData.Range(&quot;A&quot; &amp; lr).Value = wsIndex.Cells(r, 1).Value: wsData.Range(&quot;C&quot; &amp; lr).Value = &quot;ÑÞã ÇáÞÖíÉ ÛíÑ ÕÍíÍ&quot;: GoTo Skipper
              .Open &quot;POST&quot;, &quot;https://eservices.moj.gov.kw/viewResults/viewLastEvents.jsp&quot;, False
              .setRequestHeader &quot;Content-type&quot;, &quot;application/x-www-form-urlencoded&quot;
              .send
              html.body.innerHTML = .responseText
          End With
              Set html = Nothing: Set htmlData = Nothing
  Skipper:
          Application.Wait Now + TimeValue(&quot;00:00:05&quot;)
      Next r
      Application.StatusBar = Empty
      MsgBox &quot;Done...&quot;, 64
  End Sub
  </code></pre>
  <p>And this is the part the is responsible for the captcha</p>
  <pre><code>Private Sub DecryptCaptcha()
      Dim res, sDestFolder As String, strFile As String, sURL As String
      sDestFolder = ThisWorkbook.Path &amp; &quot;\&quot;
      strFile = &quot;Number.png&quot;
      sURL = &quot;https://eservices.moj.gov.kw/captcha/imgCaptcha.jsp&quot;
      With CreateObject(&quot;MSXML2.XMLHTTP&quot;)
          .Open &quot;GET&quot;, sURL, False
          .send
          res = .responseBody
      End With
      With CreateObject(&quot;ADODB.Stream&quot;)
          .Type = 1
          .Open
          .write res
          .SaveToFile sDestFolder &amp; strFile, 2
      End With
      vCaptcha = CleanNumber(ScriptFile(sDestFolder &amp; strFile))
  End Sub
  
  Function ScriptFile(strImage As String) As String
      Dim wshShell As Object, sOutput As String, strCommand As String
      sOutput = ThisWorkbook.Path &amp; &quot;\OutputNumber.txt&quot;
      strCommand = &quot;Powershell.exe -File &quot;&quot;C:\Users\&quot; &amp; Environ(&quot;USERNAME&quot;) &amp; &quot;\Desktop\ConvertImage.ps1&quot;&quot; &quot; &amp; strImage
      Set wshShell = CreateObject(&quot;WScript.Shell&quot;)
      wshShell.Run strCommand, 0, True
      ScriptFile = CreateObject(&quot;Scripting.FileSystemObject&quot;).OpenTextFile(sOutput).ReadAll
  End Function
  
  Function CleanNumber(ByVal strText As String) As String
      With CreateObject(&quot;VBScript.RegExp&quot;)
          .IgnoreCase = True
          .Global = True
          .Pattern = &quot;[^0-9]&quot;
          If .Test(strText) Then
              CleanNumber = WorksheetFunction.Trim(.Replace(strText, vbNullString))
          Else
              CleanNumber = strText
          End If
      End With
  End Function
  </code></pre>
  <p>And as for the powershell file these are the contents</p>
  <pre><code>$image=$args[0]
  $desktop= (Join-Path $env:USERPROFILE 'Desktop')
  $imagefile=(Join-Path $desktop 'NumberNew.png')
  $textfile=(Join-Path $desktop 'OutputNumber')
  
  cd (Join-Path $desktop '\')
  magick convert $image -resize 300x160 -density 300 -quality 100 $imagefile
  magick convert $imagefile -negate -lat 300x160+40% -negate $imagefile
  tesseract.exe $imagefile $textfile -l eng
  </code></pre>
  <p>Of course the code requires tesseract to be installed and also the imagemagick to deal and manipulate the image. The code is working in VBA but I would like to use python for that to improve my skills. Now I am stuck and have no more points of success. Thanks advanced for help.</p>