简体   繁体   中英

Python Requests API requests.get() call with params is not working as intended (response ignores params)

Here is my code:

 import requests find_doctors_url = 'http://www.americhoice.com/find_doctor/Ver2/results_doc.jsp' payload ={"specialty":"ORSU","docproducts":"HOBD,HLOP","planNameDropDoc":"HOBD,HLOP","plan":"uhcwa","zip":"98122","zipradius":"10","findButton":"FIND DOCTOR","specialtyName":"ORTHOPAEDIC SURGERY"} response = requests.get(find_doctors_url,params=payload) print(response.url) print(response.content) 

when I print response.content, all I receive is:

<!-- NEAADR0179 -Anil Kumar Vutikuri *** End-->


<!--BEGIN SETTING HEADERS TO NO CACHE-->

<!--END SETTING HEADERS TO NO CACHE-->

<!--SET SESSION VALUES FROM URL PARAMETERS-->


<!--END SET SESSION VALUES FROM URL PARAMETERS-->

Which is the response you receive when you navigate to: view-source: http://www.americhoice.com/find_doctor/Ver2/results_doc.jsp

However, I am seeking to return the complete html received when you navigate to the url generated by response.url

view-source: http://www.americhoice.com/find_doctor/Ver2/results_doc.jsp?specialty=ORSU&docproducts=HOBD%2CHLOP&planNameDropDoc=HOBD%2CHLOP&plan=uhcwa&zip=98122&zipradius=10&findButton=FIND+DOCTOR&specialtyName=ORTHOPAEDIC+SURGERY

The problems seems to be that the request is not sending the GET query params correctly

Things I have tried (unsuccessfully): 1)Requesting the complete URL(encoded) instead of using a params dictionary 2)Using the urllib3 library instead of the Requests library

First, the view-source website you give returns 404 error.

Second, what do you get when you print response.url ? It should return full url including params concatenated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM