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

Connection error #32

Closed
tedatkc opened this issue Dec 5, 2022 · 10 comments
Closed

Connection error #32

tedatkc opened this issue Dec 5, 2022 · 10 comments

Comments

@tedatkc
Copy link

tedatkc commented Dec 5, 2022

Problem with connecting. Is this the right way to use code? From the response? Why is connection failing?
Ref: Issue #31.

bynder_client = BynderClient(
    domain=DOMAIN,
    redirect_uri='https://localhost/callback',
    client_id=CLIENTID,
    client_secret=CLIENTSECRET,
    scopes=['offline',
            'asset:read',
            'meta.assetbank:read'],
)

print(bynder_client.get_authorization_url())
code = input('Code: ')
bynder_client.fetch_token(code)

asset_bank_client = bynder_client.asset_bank_client
media_list = asset_bank_client.media_list({
    'limit': 2,
    'type': 'image'
})

# RESPONSE:
#    ('https://https://[MYDOMAIN]/v6/authentication/
#      oauth2/auth?response_type=code&client_id=[MYCLIENTID]&
#      redirect_uri=https%3A%2F%2Flocalhost%2Fcallback.&scope=offline+asset%3Aread+
#      meta.assetbank%3Aread&state=ElNUPvMv', 'ElNUPvMv')
#
# ENTERED CODE from state above...
#    Code: ElNUPvMv
#
# ConnectionError: HTTPSConnectionPool(host='https', port=443): Max retries 
# exceeded with url: //[MYDOMAIN]/v6/authentication/oauth2/token 
# (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 11001] 
# getaddrinfo failed'))
@TimBloembergen
Copy link

TimBloembergen commented Dec 7, 2022

Hi @tedatkc When looking at the response ('https://https://[MYDOMAIN]/v6/authentication/ it looks like your passing https twice, which is why the connection is failing.

@tedatkc
Copy link
Author

tedatkc commented Dec 7, 2022

Sorry -- I should have caught that.

Still getting problems. Here is what I ran. I ran the two options for the redirect URI and still had problems. Looks like it is not even getting to the callback?

#DOMAIN='https://digitalassets.kimberly-clark.com'
DOMAIN='digitalassets.kimberly-clark.com'

#REDIRECT_URI='https://localhost/callback'
REDIRECT_URI='localhost/callback'

bynder_client = BynderClient(
    domain=DOMAIN,
    redirect_uri=REDIRECT_URI,
    client_id=CLIENTID,
    client_secret=CLIENTSECRET,
    scopes=['offline',
            'asset:read',
            'meta.assetbank:read'],
)

print(bynder_client.get_authorization_url())
code = input('Code: ')
bynder_client.fetch_token(code)

asset_bank_client = bynder_client.asset_bank_client
media_list = asset_bank_client.media_list({
    'limit': 2,
    'type': 'image'
})

Here is the response (with some replaced text):

('https://digitalassets.[my_DOMAIN].com/v6/authentication/oauth2/auth?response_type=code&client_id=[my_CLIENTID]&redirect_uri=localhost%2Fcallback&scope=offline+asset%3Aread+meta.assetbank%3Aread&state=1IDz48tG', '1IDz48tG')
Code: 1IDz48tG
Traceback (most recent call last):

  File "[my_environment]byndersdk\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(

  File "[my_environment]byndersdk\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)

  File "[my_environment]byndersdk\lib\site-packages\urllib3\connectionpool.py", line 1042, in _validate_conn
    conn.connect()

  File "[my_environment]byndersdk\lib\site-packages\urllib3\connection.py", line 414, in connect
    self.sock = ssl_wrap_socket(

  File "[my_environment]byndersdk\lib\site-packages\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(

  File "[my_environment]byndersdk\lib\site-packages\urllib3\util\ssl_.py", line 493, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)

  File "[my_environment]byndersdk\lib\ssl.py", line 513, in wrap_socket
    return self.sslsocket_class._create(

  File "[my_environment]byndersdk\lib\ssl.py", line 1071, in _create
    self.do_handshake()

  File "[my_environment]byndersdk\lib\ssl.py", line 1342, in do_handshake
    self._sslobj.do_handshake()

SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:997)


During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "[my_environment]byndersdk\lib\site-packages\requests\adapters.py", line 489, in send
    resp = conn.urlopen(

  File "[my_environment]byndersdk\lib\site-packages\urllib3\connectionpool.py", line 787, in urlopen
    retries = retries.increment(

  File "[my_environment]byndersdk\lib\site-packages\urllib3\util\retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))

MaxRetryError: HTTPSConnectionPool(host='digitalassets.[my_DOMAIN].com', port=443): Max retries exceeded with url: /v6/authentication/oauth2/token (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:997)')))


During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "[my_environment]byndersdk\lib\site-packages\spyder_kernels\py3compat.py", line 356, in compat_exec
    exec(code, globals, locals)

  File "c:\users\[my_UID]\onedrive - [my_DOMAIN]\projects\2022\fia\gre03327-40020\bynder\test\getting_started_ted.py", line 104, in 
    bynder_client.fetch_token(code)

  File "[my_environment]byndersdk\lib\site-packages\bynder_sdk\client\bynder_client.py", line 58, in fetch_token
    return self.session.fetch_token(

  File "[my_environment]byndersdk\lib\site-packages\bynder_sdk\oauth2.py", line 34, in fetch_token
    return super().fetch_token(

  File "[my_environment]byndersdk\lib\site-packages\requests_oauthlib\oauth2_session.py", line 341, in fetch_token
    r = self.request(

  File "[my_environment]byndersdk\lib\site-packages\requests_oauthlib\oauth2_session.py", line 521, in request
    return super(OAuth2Session, self).request(

  File "[my_environment]byndersdk\lib\site-packages\requests\sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)

  File "[my_environment]byndersdk\lib\site-packages\requests\sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)

  File "[my_environment]byndersdk\lib\site-packages\requests\adapters.py", line 563, in send
    raise SSLError(e, request=request)

SSLError: HTTPSConnectionPool(host='digitalassets.[my_DOMAIN].com', port=443): Max retries exceeded with url: /v6/authentication/oauth2/token (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:997)')))

@Arpit-Sharma-USC
Copy link
Contributor

@tedatkc are you using a vpn or some sort of proxy? This generally leads to ssl errors. We tested the sdk a little while ago and it is working correctly. So if you are still facing the same issue I would recommend doing a clean-up of your python environment,re-importing the package and retrying.

Here is a thread for a similar issue that might be of help https://discuss.python.org/t/ssl-certificate-verify-failed-certificate-verify-failed-self-signed-certificate/14359

@Arpit-Sharma-USC
Copy link
Contributor

Hey @tedatkc we were informed that you reached out to support about this. I want to reiterate on the fact that you please make use of the sdk methods to make calls and not setup your own session with the requests. I do understand you might be running a few checks of your own around ssl for it perhaps with that?

But looks to me that there is something missing with your ssl permissions or vpn tunneling(if you are using one). We do not have a specific ssl certificate that we need the clients to patch during usage. Like the thread above you might find a solution for the ssl issue/tunneling in a stackoverflow thread with some digging around.

@tedatkc
Copy link
Author

tedatkc commented Dec 9, 2022

My only purpose in using requests was to discover if something was wrong on my end. I discovered that my SSL certificates were wrong (being a newbie to SSL). That has now been corrected. Yay!

I'm only trying to use the most basic example -- nothing exotic, nothing outside of your "getting started" documentation. I've been trying to make use the example app.py and sdk methods trying to get things to work. The code earlier in this chain (and issue #31) was right from the documentation.

I now get: MissingTokenError: (missing_token) Missing access token parameter, from the bynder_client.fetch_token(code) call.

print(bynder_client.get_authorization_url())
code = input('Code: ')
bynder_client.fetch_token(code)

By the way, it's not clear from the documentation what I'm supposed to enter in as "Code:". The get_authorization_url() call returns a 2-tuple with the URL request and a short string. Is that what is supposed to be entered as the 'Code'? The short string?

Thank you!

@tedatkc
Copy link
Author

tedatkc commented Dec 9, 2022

Per Eric on Support 160448, I've been asked to follow up here. He also instructed me to paste the URL from the get_authorization_url() into a browser to get the code.

('https://digitalassets.kimberly-clark.com/v6/authentication/oauth2/auth?response_type=code&client_id=[MYCLIENTID]&redirect_uri=https%3A%2F%2Flocalhost%2Fcallback&scope=offline+asset%3Aread+meta.assetbank%3Aread&state=0NIKLWkx',
 '0NIKLWkx')

When I paste this URL into a browser I get the following:
image

@TimBloembergen
Copy link

Hi @tedatkc Would you be able to enable the support feature in the portal so that we can have a look at your OAuth2 app setup? The error that you receive is most likely due to the setup of the client in the portal.

https://support.bynder.com/hc/en-us/articles/360013934239-Grant-Bynder-Access-to-Your-Portal

The code that you need to generate a token is returned after you complete the login challenge after running a successful "Authorize Application". Please refer to our API documentation for more information, https://bynder.docs.apiary.io/#reference/oauth-2.0/authorize-endpoint/authorize-application

This error "I now get: MissingTokenError: (missing_token) Missing access token parameter, from the bynder_client.fetch_token(code) call." is returned because the example is trying to to an API requests while you have not setup an Access token yet.

For an OAuth2 APP - https://support.bynder.com/hc/en-us/articles/360013875180-Create-your-OAuth-Apps
You need to make sure you are enabling the proper Scopes that you need, and also setup the grant_type to the type you are running. In this case you need to setup the OAuth2 app to Authorization code + Refresh Token

Once you've the OAuth2 setup correctly you can go ahead and configure the app.py file. Like my example below.

Screenshot 2022-12-12 at 09 35 50

Once you've configured your domain, redirect_URI, client_id, client_secret, scopes you can run the code. Which will return a link that you need to open in your browser. After doing the login challenge you will be redirected to your redirectURI. That URI will have the code that you need. Copy that code in input it / set it up.

Screenshot 2022-12-12 at 09 36 13

After you copy and paste the code and run it, an Access Token will be generated which can be setup at the token on line 16 of the Example app.

All of these steps are standardised OAuth2 protocols, you can always refer to our documentation in regards to OAuth2

https://bynder.docs.apiary.io/#reference/oauth-2.0/

This information should get you on your way. I'm not sure what software you using but Pycharm is an easy way to run Python scripts, you can download it via https://www.jetbrains.com/pycharm/download/#section=mac

@tedatkc
Copy link
Author

tedatkc commented Dec 12, 2022

We're working on getting it opened up for support. Can we arrange a webex or the like to do this real time?

@tedatkc
Copy link
Author

tedatkc commented Dec 12, 2022 via email

@TimBloembergen
Copy link

Hi @tedatkc Unfortunately that level is support is not something we can provide on our SDKs. We can confirm that the SDK is working and there's nothing broken in it. I think this is just a matter of setup, we don't have the technical resources to get on a call to live troubleshoot.
With the steps I've provided you should get the SDK up and running on your local machine. Deploying and running the SDK on a server environment is not something we could assist with. If you'd download the tool I mentioned, all you'd have to do it open the project, input your client information that can be generated in the portal and put it in there.

Doing those steps outlined above should get you on your way.

What I can do is is that if you sent me your app.py file so that I can have a look and see if it runs on my machine. To do this you can send it to [email protected]. Please leave your clientid & secret in there otherwise I won't be able run it.

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