2

I would like to access a ressource with a particular url. Let's say I have only access to a PC (without admin rights) from which I cannot use the requests module due to different reasons.

Normally, I would address an API und perform HTTP GET and HTTP POST requests with:

import requests
url = r"https://httpbin.org/json"
r = requests.get(url)

If I would like to provide header and authorisation details, I would add

headers = {"Content-Type": "application/json"}
auth = ("username", "password")
r = requests.post(url, auth=auth, headers=headers)

as well as the payload in the data exchange format of the API (either JSON or XML).

Unfortunately, I cannot use the requests module on the aforementioned system. However, I can use the selenium module with the Internet Explorer webdriver (no Firefox and no Chrome).

I tried to access the url of the API with

from selenium import webdriver
driver = webdriver.Ie()
driver.get(url)

This does open an authentication popup, which I cannot access with the selenium "switch_to" functions. Ideally, I would like to perform a HTTP POST via selenium and provide authentication as well as header information. Would that be possible?

xaneon
  • 317
  • 3
  • 9
  • Check the link if that helps : [https://stackoverflow.com/questions/25491541/python3-json-post-request-without-requests-library] – KunduK Apr 06 '20 at 16:37
  • 1
    you can execute javascript to send the get or post. – pcalkins Apr 06 '20 at 17:53
  • Thank you very much for your comments. @KunduK: unfortunately, this would not work due to a similar reason as in the case of the request module. Both are building on `urllib` and there seems to be a problem with either closed ports or proxy settings I cannot access on this machine. I will try to perform the get and post requests with javascript. Do you have any other ideas? – xaneon Apr 07 '20 at 07:31

0 Answers0