Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to connect to protected WebService (Basic Authentication) #5

Closed
madEng84 opened this issue Jun 11, 2018 · 7 comments
Closed

How to connect to protected WebService (Basic Authentication) #5

madEng84 opened this issue Jun 11, 2018 · 7 comments

Comments

@madEng84
Copy link

madEng84 commented Jun 11, 2018

Hi,
I want to connect to a protected webservice (BasicAuthentication)

What is the right approach?

I have tried this

from requests.auth import _basic_auth_str
from suds.client import Client
from suds.cache import NoCache

my_client = Client(WSDL_URL, 
                  location=WSDL_URL, 
                  cache=NoCache(), 
                  headers={'Authorization':_basic_auth_str(username,password)})

but without luck

Thank you in advance

@madEng84 madEng84 changed the title How to connect to protected WebService How to connect to protected WebService (Basic Authentication) Jun 11, 2018
@madEng84
Copy link
Author

I resolved it but i think that the problem is that it is not well documented...

from requests.auth import _basic_auth_str
from suds.client import Client
from suds.cache import NoCache
from suds.transport.https import HttpAuthenticated

my_client = Client(WSDL_URL, 
                  location=WSDL_URL, 
                  cache=NoCache(), 
                  transport={'Authorization':HttpAuthenticated(username='<username>',password='<password>')})

@rmarzocchi84
Copy link

rmarzocchi84 commented Nov 29, 2019

I have only a token header and I try with the following lines:

from requests.auth import _basic_auth_str
from suds.client import Client
from suds.cache import NoCache
from suds.transport.https import HttpAuthenticated
my_client = Client(WSDL_URL, 
                  location=WSDL_URL, 
                  cache=NoCache(), 
                  transport={'Authorization':HttpAuthenticated(Authorization='Bearer 10ac7b40-c252-3544-9b5e-301836e485a5')})

but I encountered a strange error

Traceback (most recent call last):
  File "test_ws2.py", line 18, in <module>
    transport={'Authorization':HttpAuthenticated(Authorization='Bearer 10ac7b40-c252-3544-9b5e-301836e485a5')})
  File "/usr/local/lib/python3.6/site-packages/suds/transport/https.py", line 57, in __init__
    HttpTransport.__init__(self, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/suds/transport/http.py", line 56, in __init__
    Unskin(self.options).update(kwargs)
  File "/usr/local/lib/python3.6/site-packages/suds/properties.py", line 255, in update
    self.set(n, v)
  File "/usr/local/lib/python3.6/site-packages/suds/properties.py", line 280, in set
    self.provider(name).__set(name, value)
  File "/usr/local/lib/python3.6/site-packages/suds/properties.py", line 419, in __set
    d = self.definition(name)
  File "/usr/local/lib/python3.6/site-packages/suds/properties.py", line 241, in definition
    raise AttributeError(name)
AttributeError: Authorization

@rmarzocchi84
Copy link

@madEng84 have you any suggestion to call a webservice with an authorization token of this type: "Bearer Xxxx"

@madEng84
Copy link
Author

@rmarzocchi84 I cannot find a similar solution to the one i used, but i see in this library code that "authorization" is a not expected key for HttpAuthenticated.init method. Maybe you have to write your own implementation.

Before it, try with an approach like this
https://stackoverflow.com/questions/36352790/calling-soap-clientsuds-in-python-returning-error-authenticationerror-login-co

Keep me informed

@charn
Copy link
Member

charn commented Dec 19, 2019

Looks like the HttpAuthenticated is not correctly initialized. I'm not sure if the following actually works, but maybe something like this might solve the problem?

my_client = Client(
    WSDL_URL, 
    location=WSDL_URL, 
    cache=NoCache(), 
    transport=HttpAuthenticated(
        headers={"Authorization" : "Bearer 10ac7b40-c252-3544-9b5e-301836e485a5"}
    ),
)

@rmarzocchi84
Copy link

Before it, try with an approach like this
https://stackoverflow.com/questions/36352790/calling-soap-clientsuds-in-python-returning-error-authenticationerror-login-co

I have already tested this solution --> HTTP Error 405: Method Not Allowed

@rmarzocchi84
Copy link

Just dry-coding here, but would the following work

my_client = Client(
    WSDL_URL, 
    location=WSDL_URL, 
    cache=NoCache(), 
    transport=HttpAuthenticated(
        headers={"Authorization" : "Bearer 10ac7b40-c252-3544-9b5e-301836e485a5"}
    ),
)

I try it (removing cache=NoCache()).. and finally I encountered the
HTTP Error 405: Method Not Allowed like in this issue suds-community/suds#27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants