sam mathew
sam mathew

Reputation: 35

Python Requests not able to retrieve data from a API

Please find the below code

data={
    "OptPersonFacility": "Facility",
    "ProfessionID":"3",
    "LicenseTypeId": "258",
    "State": "",
    "Country": "ALL",
    "County": "null",
    "IsFacility": "1",
    "PersonId": "null",
    "PageNo": "1",
    }
response=session.post("https://www.pals.pa.gov/api/Search/SearchForPersonOrFacilty",data=data)

Am getting the response as

{
"Message": "An error has occurred."
}

Actual required response:

[{"IsFacility":0,"FirstName":"","MiddleName":"","LastName":"","FacilityName":"A F MCGERVEY & CO LLC","ProfessionID":null,"LicenseTypeId":null,"LicenseNumber":"AF000392L","LicenceType":"Accountancy Firm","ProfessionType":"Accountancy","Status":"Active","AddressLine1":null,"AddressLine2":null,"City":"PITTSBURGH","State":"Pennsylvania","County":"Allegheny","Country":"United States","zipcode":"15236","OptPersonFacility":null,"FullName":null,"PersonId":14551,"FacilityStreetAddress":"5329 BROWNSVILLE ROAD   PITTSBURGH PA 15236","DisciplinaryActionTypeId":null,"DisciplinaryAction":null,"ComplaintNumber":null,"ComplaintFromDate":"0001-01-01T00:00:00","ComplaintToDate":"0001-01-01T00:00:00","AddressLine3":"","AddressLine4":"PITTSBURGH, PA 15236","CountryShortCode":"UNITED_STATES","BoardName":"State Board of Accountancy","RequestedFileName":null,"RequestedFileId":null,"LicenseId":961054,"RecaptchaResponse":"","Row":1,"PageNo":0,"TotalRecords":4400,"NameSuffix":"","PhoneNo1":"","Emailid1":"","McareDocketNumber":"","McareCourtFiled":"","McareServed":"","FictitiousName":"","DoingBusinessAs":"","IsPersonFacility":false,"ComplaintCloseDate":null}]

Did i miss anything ?

Upvotes: 1

Views: 175

Answers (1)

QHarr
QHarr

Reputation: 84465

I did without Session and sent as actual json and replaced Null with empty string literals

import requests

data = {"OptPersonFacility":"Facility","ProfessionID":3,"LicenseTypeId":258,"State":"","Country":"ALL","County":"","IsFacility":1,"PersonId":"","PageNo":1}
r = requests.post('https://www.pals.pa.gov/api/Search/SearchForPersonOrFacilty', json=data).json()
print(r)

Upvotes: 1

Related Questions