0

I have the following code which works as is. What I need to set the HTTPS authentication in the header. To keep the question clean, just accept the fact that the python requests module can’t be used because of what the vendor did to wrap the Jython runtime. The Java Classes are at Java 8.

  def getAllSafes (self, authenticationBaseURL, sessionToken):
      wwJO = Json.createObjectBuilder().build()
      offset = 0
      limit = 10
      sort = "asc" # ascending
      includeAccounts = "true"
      extendedDetails = "true"
      
      get_allSafes_url = "https://" + authenticationBaseURL + "/PasswordVault/api/Safes?" + "includeAccounts=" + includeAccounts + "&offset=" + str(offset) + "&limit=" + str(limit) + "&sort=" + sort + "&extendedDetails=" + extendedDetails
      wwJO = Json.createObjectBuilder().build()

      vault_url = URL(get_allSafes_url)
      isr = InputStreamReader(vault_url.openStream())
      JsonReader = Json.createReader(isr)

      print JsonReader.readObject()
      JsonReader.close()
      return "_Determined at run time_"
      
paulhr
  • 339
  • 4
  • 17
  • Do you need to set an authorization header? See: https://stackoverflow.com/questions/33912074/https-get-using-jython – Curtis May 05 '21 at 14:04
  • Yes the authorization header is needed. I can't use urllib2 because the cacert file parameter did not get included until after version 2.7.0. I am stuck on 2.7.0 with no way to update because the way the vendor imbedded jython in their product. – paulhr May 05 '21 at 14:51

1 Answers1

0

Try this snippet of code to set the Authorization header (you'll need to supply the authorizationvalue):

    vault_url = URL(get_allSafes_url)
    connection = vault_url.openConnection()
    connection.setRequestProperty("Authorization", authorizationvalue)
    isr = InputStreamReader(connection.getInputStream())
Curtis
  • 548
  • 3
  • 13
  • Not working. I get the following. Results in the following output… wwMap.size():14 wwHeader:None wwHeader:X-Content-Type-Options wwHeader:Pragma wwHeader:Date wwHeader:X-UA-Compatible wwHeader:Strict-Transport-Security wwHeader:Access-Control-Expose-Headers wwHeader:Cache-Control wwHeader:Set-Cookie wwHeader:X-FRAME-Options wwHeader:Expires wwHeader:X-XSS-Protection wwHeader:Content-Length wwHeader:Content-Type – paulhr May 07 '21 at 13:24
  • My bad. The "Authentication" header can not be returned, see. https://stackoverflow.com/questions/22726697/httpsurlconnection-getheaderfields-not-returning-set-cookie – paulhr May 07 '21 at 14:51