Tuesday, 19 September 2023

Getting 'Error Processing Request' while sending Post Request to website (python)

I'm trying to send Post request to website. Website contains Cloudflare but I'm using Zenrows Client to pypass it.

I'm using VS Code and Python 3 - with beautifulsoup for parsing.

First I'm sending Get request to startpage - from where I'm getting link of homepage.

Code:

from zenrows import ZenRowsClient
from bs4 import BeautifulSoup


client = ZenRowsClient("my-zenrows-api")
startpageUrl = "https://www.ohiosos.gov/notary/"
params = {"js_render":"true","antibot":"true","premium_proxy":"true","proxy_country":"us"}

startpageResponse = client.get(startpageUrl, params=params)


print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ startpageResponse $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")

print(startpageResponse.text)

startpageSoup = BeautifulSoup(startpageResponse.text, 'html.parser')

links = startpageSoup.find_all('a', class_="block-link-list__link balance-text")

homepageUrl = links[3].get('href')

print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ homepageUrl $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")

print(homepageUrl)

At this point I've got url for the homepage which is:

https://notarysearch.ohiosos.gov/ords/f?p=ENSEARCH:SEARCH:5261990181730:::1::

Then I've used above homepage link and send Get request to homepage and get cookies and other required things which I need to send with searchpage request.

Code:

homepageResponse = client.get(homepageUrl, params=params)


homepageCookiesContent = homepageResponse.headers.get('Zr-Cookies')


homepageCookies = homepageCookiesContent.split(';')

sessionCookieContent = homepageCookies[0].split('=')
sessionCookieName = sessionCookieContent[0]
sessionCookie = sessionCookieContent[1]

cf_bmCookieContent = homepageCookies[1].split('_bm=')
cf_bmCookie = cf_bmCookieContent[1]

print(sessionCookieName)
print(sessionCookie)
print(cf_bmCookie)

cookieHeader = sessionCookieName + "=" + sessionCookie + "; __cf_bm=" + cf_bmCookie

print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ cookieHeader $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")

print(cookieHeader)


homepageSoup = BeautifulSoup(homepageResponse.text, 'html.parser')

p_flow_id = homepageSoup.find('input', attrs={'name': 'p_flow_id'}).get('value')
p_flow_step_id = homepageSoup.find('input', attrs={'name': 'p_flow_step_id'}).get('value')
p_instance = homepageSoup.find('input', attrs={'name': 'p_instance'}).get('value')
p_page_submission_id = homepageSoup.find('input', attrs={'name': 'p_page_submission_id'}).get('value')
pPageItemsProtected = homepageSoup.find('input', attrs={'id': 'pPageItemsProtected'}).get('value')


print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ Inputs $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")

print("p_flow_id",p_flow_id)
print("p_flow_step_id",p_flow_step_id)
print("p_instance",p_instance)
print("p_page_submission_id",p_page_submission_id)
print("pPageItemsProtected",pPageItemsProtected)

Output:

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ cookieHeader $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
ORA_WWV_APP_36732724=ORA_WWV-lRqp0oGpHAhH92k2iYZbDkeC; __cf_bm=Uc1Jv9puWwdWN0vnlkE6Nlm_TTd1BpjPfsaPfr7Z6Go-1693985831-0-Ab7q0Qj0v3Um1MYxidwGoKN/A86Xl/gmtvpcLyr7hYJUj/bGk970zgocGuHxLooinEtTD5+ykJetq2kq798h9TM=

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ Inputs $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
p_flow_id 36732724
p_flow_step_id 1
p_instance 10300785208268
p_page_submission_id 298323213103614456903500441489133252459
pPageItemsProtected 7BZkzG0HyWZTls0GlxvD0g

Then I use above cookies and inputs to create header and payload - and send Post request.

Code:

referer = "https://notarysearch.ohiosos.gov/ords/f?p=ENSEARCH:SEARCH:" + p_instance + ":::1::"
    
headers = {
    "Host": "notarysearch.ohiosos.gov",
    "Accept": "application/json, text/javascript, */*; q=0.01",
    "Accept-Encoding": "gzip, deflate, br",
    "Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8",
    "Content-Length": "548",
    "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
    "Cookie": cookieHeader, 
    "Origin": "https://notarysearch.ohiosos.gov",
    "Referer": referer,
    "Sec-Ch-Ua": "\"Not.A/Brand\";v=\"8\", \"Chromium\";v=\"114\", \"Google Chrome\";v=\"114\"",
    "Sec-Ch-Ua-Mobile": "70",
    "Sec-Ch-Ua-Platform": "\"Linux\"",
    "Sec-Fetch-Dest": "empty",
    "Sec-Fetch-Mode": "cors",
    "Sec-Fetch-Site": "same-origin",
    "X-Requested-With": "XMLHttpRequest"
}


p_json = {
    "pageItems": {
        "itemsToSubmit": [
            {"n": "P1_FIRST_NAME", "v": "ab"},
            {"n": "P1_LAST_NAME", "v": ""},
            {"n": "P1_ONLINE_NOTARY", "v": "ALL"}
        ],
        "protected": pPageItemsProtected,
        "rowVersion": ""
    },
    "salt": p_page_submission_id  # Use the actual p_page_submission_id value
}


data = {
    "p_flow_id": p_flow_id,
    "p_flow_step_id": p_flow_step_id,
    "p_instance": p_instance,
    "p_debug": "",
    "p_request": "SEARCH",
    "p_reload_on_submit": "S",
    "p_page_submission_id": p_page_submission_id,
    "p_json": p_json
    }

print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ data $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")

print(data)

searchPageUrl="https://notarysearch.ohiosos.gov/ords/wwv_flow.accept"

serchpageResponse = client.post(searchPageUrl, params=params, data=data, headers=headers)

print(serchpageResponse.text)

Output:

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ data $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
{'p_flow_id': '36732724', 'p_flow_step_id': '1', 'p_instance': '10300785208268', 'p_debug': '', 'p_request': 'SEARCH', 'p_reload_on_submit': 'S', 'p_page_submission_id': '298323213103614456903500441489133252459', 'p_json': {'pageItems': {'itemsToSubmit': [{'n': 'P1_FIRST_NAME', 'v': 'ab'}, {'n': 'P1_LAST_NAME', 'v': ''}, {'n': 'P1_ONLINE_NOTARY', 'v': 'ALL'}], 'protected': '7BZkzG0HyWZTls0GlxvD0g', 'rowVersion': ''}, 'salt': '298323213103614456903500441489133252459'}}

<!DOCTYPE html>
<html class="no-js  page-1 app-ENSEARCH" lang="en" >
.
.
.
<body class="t-PageBody--login no-anim   apex-top-nav apex-icons-fontapex"  >
<form action="wwv_flow.accept" method="post" name="wwv_flow" id="wwvFlowForm" novalidate  autocomplete="off">
<input type="hidden" name="p_flow_id" value="36732724" id="pFlowId" /><input type="hidden" name="p_flow_step_id" value="1" id="pFlowStepId" /><input type="hidden" name="p_instance" value="10300785208268" id="pInstance" /><input type="hidden" name="p_page_submission_id" value="210454894249743044597745821015635543897" id="pPageSubmissionId" /><input type="hidden" name="p_request" value="" id="pRequest" /><input type="hidden" name="p_reload_on_submit" value="S" id="pReloadOnSubmit" /><input type="hidden" value="210454894249743044597745821015635543897" id="pSalt" /><div class="t-Body">
  
  
  <div class="t-Body-wrap">
    <div class="t-Body-col t-Body-col--main">
      <div class="t-Login-container" role="main">
      <div class="t-Alert t-Alert--danger t-Alert--wizard t-Alert--defaultIcons">
  <div class="t-Alert-wrap">
    <div class="t-Alert-icon">
      <span class="t-Icon"></span>
    </div>
    <div class="t-Alert-content">
      <div class="t-Alert-body">
        <h3>Error processing request.</h3>
        <p>Contact your application administrator.</p>
        <div class="t-Alert-inset"></div>
      </div>
    </div>
    <div class="t-Alert-buttons">
      <button onclick="javascript:window.history.go(-1)" class="t-Button t-Button--hot w50p t-Button--large" type="button">OK</button>
    </div>
  </div>
</div>
      </div>
    </div>
  </div>
</div></form>


<script>
var apex_img_dir = "/i/", htmldb_Img_Dir = apex_img_dir;
</script>
<script src="/i/libraries/apex/minified/desktop_all.min.js?v=18.2.0.00.12"></script>
<script src="wwv_flow.js_messages?p_app_id=36732724&p_lang=en&p_version=18.2.0.00.12-2315523062089"></script>


<script src="/i/libraries/apex/minified/widget.stickyWidget.min.js?v=18.2.0.00.12"></script>
<script src="/i/themes/theme_42/1.2/js/theme42.min.js?v=18.2.0.00.12"></script>



  




<script type="text/javascript">
apex.jQuery( function() {
apex.page.init( this, function() {
apex.jQuery.when.apply( apex.jQuery, apex.page.loadingDeferreds ).done(function() {
try {
apex.theme42.initializePage.appLogin();
} finally {
apex.event.trigger(apex.gPageContext$,'apexreadyend');
}
});
});
});</script>

</body>
</html>

It is giving some 'Error Processing Request'.

I think the problem is, when I search something on searchpage (via browser like chrome) it sends post request to 'https://ift.tt/bfgDvMO' but in it's response there is nothing. When I check it after opening inspect and network tab of chrome. Post request is going to 'https://ift.tt/bfgDvMO' but there is another page opening 'https://ift.tt/PbwL4hf' here in its response there is data.

What my above code is doing - sending Post request to 'https://ift.tt/bfgDvMO' and I was hoping it will automatically redirect to 'https://ift.tt/PbwL4hf' but its not doing this.

Then I tried to send request via code to 'https://ift.tt/PbwL4hf' - where the number which this url is using is p_instance which I'm getting from homepage.

Code:

print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ Get Request to p_instance $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")

searchpageGetUrl = "https://notarysearch.ohiosos.gov/ords/f?p=ENSEARCH:SEARCH:" + p_instance + "::NO:RP::"

print(searchpageGetUrl)

searchpageReferer = "https://notarysearch.ohiosos.gov/ords/f?p=ENSEARCH:SEARCH:" + p_instance + ":::1::"

print(searchpageReferer)

searchpageHeaders = {
    "Host": "notarysearch.ohiosos.gov",
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
    "Accept-Encoding": "gzip, deflate, br",
    "Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8",
    "Cookie": cookieHeader, 
    "Referer": searchpageReferer,
    "Sec-Ch-Ua": "\"Not.A/Brand\";v=\"8\", \"Chromium\";v=\"114\", \"Google Chrome\";v=\"114\"",
    "Sec-Ch-Ua-Mobile": "70",
    "Sec-Ch-Ua-Platform": "\"Linux\"",
    "Sec-Fetch-Dest": "document",
    "Sec-Fetch-Mode": "navigate",
    "Sec-Fetch-Site": "same-origin",
    "Sec-Fetch-User": "?1",
    "Upgrade-Insecure-Requests": "1"
    # "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
}


searchpageGetRequest = client.get(searchpageGetUrl, params=params, headers=searchpageHeaders)

print(searchpageGetRequest.text)

Output:

https://notarysearch.ohiosos.gov/ords/f?p=ENSEARCH:SEARCH:10300785208268::NO:RP::
https://notarysearch.ohiosos.gov/ords/f?p=ENSEARCH:SEARCH:10300785208268:::1::

<!DOCTYPE html><html class="no-js  page-1 app-ENSEARCH" lang="en"><head>
  <meta http-equiv="x-ua-compatible" content="IE=edge">
  <meta charset="utf-8">
  <title>Notary Commission System - Search</title>
.
.
.
</html>
giving document of homepage - not actual data of searchpage.

Guide me where I'm doing wrong?

Any help is appreciated.



from Getting 'Error Processing Request' while sending Post Request to website (python)

No comments:

Post a Comment