Facing urlencoding issue while processing request

SIM

I've written a script in python to scrape some information from a webpage. The site requires get request method. The issue I'm facing at this moment is that as the parameters is needed to be merged with url so it should properly be urlencoded. This is where I'm stuck. I can't properly encode it to get a valid response. I gave a try but it doesn't bring any

The script I was trying with:

import requests
import urllib.parse

fields ={
'/API/api/v1/Search/Properties/?f':'319 lizzie','ty':'2018','pvty':'2017','pn':'1','st':'9','so':'1','pt':'RP;PP;MH;NR','take':'20','skip':'0','page':'1','pageSize':'20'
}
payload = urllib.parse.quote_plus(fields, safe='', encoding=None, errors=None)

headers={
"User-Agent":"Mozilla/5.0"
}

page = requests.get("http://search.wcad.org/Proxy/APIProxy.ashx?", params=payload, headers=headers)
print(page.json())

The above URL should look like this:

http://search.wcad.org/Proxy/APIProxy.ashx?/API/api/v1/Search/Properties/?f=319%20LIZZIE&ty=2018&pvty=2017&pn=1&st=9&so=1&pt=RP%3BPP%3BMH%3BNR&take=20&skip=0&page=1&pageSize=20

to get the response.

Btw, this is the error I'm having with my existing script:

Traceback (most recent call last):
  File "C:\Users\ar\AppData\Local\Programs\Python\Python35-32\Social.py", line 9, in <module>
    payload = urllib.parse.quote_plus(fields, safe='', encoding=None, errors=None)
  File "C:\Users\ar\AppData\Local\Programs\Python\Python35-32\lib\urllib\parse.py", line 728, in quote_plus
    string = quote(string, safe + space, encoding, errors)
  File "C:\Users\ar\AppData\Local\Programs\Python\Python35-32\lib\urllib\parse.py", line 712, in quote
    return quote_from_bytes(string, safe)
  File "C:\Users\ar\AppData\Local\Programs\Python\Python35-32\lib\urllib\parse.py", line 737, in quote_from_bytes
    raise TypeError("quote_from_bytes() expected bytes")
TypeError: quote_from_bytes() expected bytes
Tomalak

This works. As the documentation indicates, there is no need to do any URL encoding yourself.

The point is that the query string begins at the last question mark, not at the first. Including the second question mark in the URL is mandatory, as requests does only adds one when there isn't one there already.

import requests

url = "http://search.wcad.org/Proxy/APIProxy.ashx?/API/api/v1/Search/Properties/?"
params = {'f':'319 lizzie','ty':'2018','pvty':'2017','pn':'1','st':'9','so':'1','pt':'RP;PP;MH;NR','take':'20','skip':'0','page':'1','pageSize':'20'}

response = requests.get(url, params)

response.json()

results in

{
    'ResultList': [{
        'PropertyQuickRefID': 'R016698',
        'PartyQuickRefID': 'O0485204',
        'OwnerQuickRefID': 'R016698',
        'LegacyID': None,
        'PropertyNumber': 'R-13-0410-0620-50000',
        'OwnerName': 'GOOCH, PHILIP L',
        'SitusAddress': '319 LIZZIE ST, TAYLOR, TX  76574',
        'PropertyValue': 46785.0,
        'LegalDescription': 'DOAK ADDITION, BLOCK 62, LOT 5',
        'NeighborhoodCode': 'T541',
        'Abstract': None,
        'Subdivision': 'S3564 - Doak Addition',
        'PropertyType': 'Real',
        'ID': 0,
        'Text': None,
        'TaxYear': 2018,
        'PropertyValueTaxYear': 2017
    }],
    'HasMoreData': False,
    'TotalPageCount': 1,
    'CurrentPage': 1,
    'RecordCount': 1,
    'SearchText': '319 lizzie',
    'PagingHandledByCaller': False,
    'TaxYear': 2018,
    'PropertyValueTaxYear': 0
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Facing issue while login redirect

From Dev

Facing warning issue while debugging

From Dev

Facing issue while sending "&" in a string

From Dev

facing issue while populating/referencing the variable in shell

From Dev

Facing issue while deserializing the http resposne

From Dev

facing issue while formating the JSON Data

From Dev

Facing issue with MFA while adding account to Yodlee

From Dev

Facing issue while installing ruamel.yaml

From Dev

NodeJs facing the issue while using async waterfall

From Dev

Facing issue while installing Cassandra on MacOs

From Dev

Facing issue while calling @viewchild in angular

From Dev

Facing issue while running Daml scenarios

From Dev

Facing connection issue while running copy in Vertica

From Dev

Facing issue while starting Controller in Docker

From Dev

Facing issue while executing the groovy code in JMeter

From Dev

Facing issue while executing the Groovy code

From Dev

Facing an issue while learning logical ML

From Dev

urlEncoding issue with Swift Odata

From Java

Spring integration : Facing issue while updating the header value again

From Mysql

Facing issue while configuring MySql with apache airflow in Hadoop

From Linux

Facing GCC installation issue while setting up airflow on hadoop cluster

From Mysql

Facing issue while configuring MySql with apache airflow in Hadoop

From Dev

Facing strange issue while executing Oracle Stored procedure

From Dev

Facing an issue while making a lexical analyzer for C++ code in Python

From Dev

Facing issue KeyError while formatting string which contains JSON

From Dev

Facing issue while installing Keystone@next 4.0 beta

From Dev

Facing issue while replacing substring in string in a dataframe using python 3.4.4

From Dev

facing an issue while compiling code that uses C++ map

From Dev

Facing issue in Shell while executing query on remote postgres database

Related Related

  1. 1

    Facing issue while login redirect

  2. 2

    Facing warning issue while debugging

  3. 3

    Facing issue while sending "&" in a string

  4. 4

    facing issue while populating/referencing the variable in shell

  5. 5

    Facing issue while deserializing the http resposne

  6. 6

    facing issue while formating the JSON Data

  7. 7

    Facing issue with MFA while adding account to Yodlee

  8. 8

    Facing issue while installing ruamel.yaml

  9. 9

    NodeJs facing the issue while using async waterfall

  10. 10

    Facing issue while installing Cassandra on MacOs

  11. 11

    Facing issue while calling @viewchild in angular

  12. 12

    Facing issue while running Daml scenarios

  13. 13

    Facing connection issue while running copy in Vertica

  14. 14

    Facing issue while starting Controller in Docker

  15. 15

    Facing issue while executing the groovy code in JMeter

  16. 16

    Facing issue while executing the Groovy code

  17. 17

    Facing an issue while learning logical ML

  18. 18

    urlEncoding issue with Swift Odata

  19. 19

    Spring integration : Facing issue while updating the header value again

  20. 20

    Facing issue while configuring MySql with apache airflow in Hadoop

  21. 21

    Facing GCC installation issue while setting up airflow on hadoop cluster

  22. 22

    Facing issue while configuring MySql with apache airflow in Hadoop

  23. 23

    Facing strange issue while executing Oracle Stored procedure

  24. 24

    Facing an issue while making a lexical analyzer for C++ code in Python

  25. 25

    Facing issue KeyError while formatting string which contains JSON

  26. 26

    Facing issue while installing Keystone@next 4.0 beta

  27. 27

    Facing issue while replacing substring in string in a dataframe using python 3.4.4

  28. 28

    facing an issue while compiling code that uses C++ map

  29. 29

    Facing issue in Shell while executing query on remote postgres database

HotTag

Archive