Response 403: Error: b'{"detail": "You do not have permission to access this resource..."

We are attempting to configure our API request for our Smartfile Appliance via Python and receive the following:


Response 403: Error: b'{"detail": "You do not have permission to access this resource. You may need to login or otherwise authenticate the request."}'

Any help would be appreciated.

5replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Hello Scott, 

    Are you using our `client-python` library? I am also curious as to what type of authentication you are using. Our API requires Basic or Oauth. If you could post your code with your token removed, that would be greatly appreciated. 

    Reply Like
  • Taylor Brazelton 

    We are using SmartFile's Python client library while using Basic Authentication.

    Our code exactly mirrors what SmartFile has on the download page for the Python stuff:

     

    from smartfile import BasicClient
    
    import pprint
    
    
    api = BasicClient('Key', 'Password')
    
    pprint.pprint(api.get('/ping'))
    
    pprint.pprint(api.get('/path/info', '/'))


    Using this, the “ping” works, so we know the Python client was installed successfully, but we are getting a 403 error when I try to use anything other than ping.

    Here are the full results from when we run this code:

    "C:\Program Files (x86)\python.exe" "C:/Users/Tlebeau/Dropbox/Work Stuff/PyCharmProjects/TestPFAPI/SFTP API Test.py"

    {'ping': 'pong'}

    Traceback (most recent call last):

      File "C:/Users/<username>/Dropbox/Work Stuff/PyCharmProjects/TestPFAPI/SFTP API Test.py", line 9, in <module>

        pprint.pprint(api.get('/path/info', '/'))

      File "C:\Program Files (x86)\lib\site-packages\smartfile\__init__.py", line 125, in get

        return self._request('get', endpoint, id=id, params=kwargs)

      File "C:\Program Files (x86)\lib\site-packages\smartfile\__init__.py", line 110, in _request

        return self._do_request(request, url, **kwargs)

      File "C:\Program Files (x86)\lib\site-packages\smartfile\__init__.py", line 207, in _do_request

        return super(BasicClient, self)._do_request(*args, **kwargs)

      File "C:\Program Files (x86)\lib\site-packages\smartfile\__init__.py", line 58, in _do_request

        raise ResponseError(response)

    smartfile.errors.ResponseError: Response 403: Error: b'{"detail": "You do not have permission to access this resource. You may need to login or otherwise authenticate the request."}'

    Process finished with exit code 1


    Does SmartFile's client work in Python 3? Or does it require Python 2? We are currently running it in a Python 3.6 IDE.

    Reply Like 1
  • Taylor Brazelton 

    Any chance you've had an opportunity to review this? We're implementing close to 1500 users and would like assistance we can easily include them in multiple groups. Thank you in advance.

    Reply Like 1
  • Hello Scott Zavrel 

    Sorry for the delay in response. 

    I just tested the same code out locally in a `virtualenv` and had success against our cloud product. From that result, I am concluding that it might be an issue with our library and knowing which resource you are wanting to access. Perhaps the framework is accessing the wrong URL instead of the appliance you are wanting it to connect to. It seems by default the SDK is set up to access our cloud product by default.

    Is the appliance you are connecting to an on-prem/virtual unit or have a custom domain?

    If you would try the following for me and then post the results I think we can get this working. When initializing the BasicClient class can you pass in the URL of your appliance like the following:
     

    from smartfile import BasicClient
    
    import pprint
    
    
    api = BasicClient('Key', 'Password', url='https://app.smartfile.com')
    
    pprint.pprint(api.get('/ping'))
    
    pprint.pprint(api.get('/path/info', '/'))

    Replacing `https://app.smartfile.com` with the URL of your appliance. 

    Reply Like
  • Taylor Brazelton 

    Our appliance is virtually hosted by SmartFile and the domain was created by our organization which we then provided the certificates to Smartfile when the appliance was configured.
     

    When using:

    from smartfile import BasicClient
    import pprint
    api = BasicClient('key', 'password', url='https://temp.powerfaids.org/')
    pprint.pprint(api.get('/ping'))
    pprint.pprint(api.get('/path/info', '/'))

     

    We get this:

    "C:\Program Files (x86)\python.exe" "C:/Users/<username>/Dropbox/Work Stuff/PyCharmProjects/TestPFAPI/SFTP API Test.py"

    Traceback (most recent call last):

      File "C:\Users\<username>\AppData\Roaming\Python\Python36\site-packages\urllib3\connectionpool.py", line 601, in urlopen

        chunked=chunked)

      File "C:\Users\<username>\AppData\Roaming\Python\Python36\site-packages\urllib3\connectionpool.py", line 346, in _make_request

        self._validate_conn(conn)

      File "C:\Users\<username>\AppData\Roaming\Python\Python36\site-packages\urllib3\connectionpool.py", line 850, in _validate_conn

        conn.connect()

      File "C:\Users\<username>\AppData\Roaming\Python\Python36\site-packages\urllib3\connection.py", line 326, in connect

        ssl_context=context)

      File "C:\Users\<username>/\AppData\Roaming\Python\Python36\site-packages\urllib3\util\ssl_.py", line 329, in ssl_wrap_socket

        return context.wrap_socket(sock, server_hostname=server_hostname)

      File "C:\Program Files (x86)\lib\ssl.py", line 407, in wrap_socket

        _context=self, _session=session)

      File "C:\Program Files (x86)\lib\ssl.py", line 814, in __init__

        self.do_handshake()

      File "C:\Program Files (x86)\lib\ssl.py", line 1068, in do_handshake

        self._sslobj.do_handshake()

      File "C:\Program Files (x86)\lib\ssl.py", line 689, in do_handshake

        self._sslobj.do_handshake()

    ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)

     

    During handling of the above exception, another exception occurred:

     

    Traceback (most recent call last):

      File "C:\Users\<username>\AppData\Roaming\Python\Python36\site-packages\requests\adapters.py", line 440, in send

        timeout=timeout

      File "C:\Users\<username>\AppData\Roaming\Python\Python36\site-packages\urllib3\connectionpool.py", line 639, in urlopen

        _stacktrace=sys.exc_info()[2])

      File "C:\Users\<username>\AppData\Roaming\Python\Python36\site-packages\urllib3\util\retry.py", line 388, in increment

        raise MaxRetryError(_pool, url, error or ResponseError(cause))

    urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='temp.powerfaids.org', port=443): Max retries exceeded with url: /api/2/ping/ (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)'),))

     

    During handling of the above exception, another exception occurred:

     

    Traceback (most recent call last):

      File "C:\Program Files (x86)\lib\site-packages\smartfile\__init__.py", line 53, in _do_request

        response = request(url, stream=True, **kwargs)

      File "C:\Users\<username>\AppData\Roaming\Python\Python36\site-packages\requests\api.py", line 72, in get

        return request('get', url, params=params, **kwargs)

      File "C:\Users\<username>\AppData\Roaming\Python\Python36\site-packages\requests\api.py", line 58, in request

        return session.request(method=method, url=url, **kwargs)

      File "C:\Users\<username>\AppData\Roaming\Python\Python36\site-packages\requests\sessions.py", line 508, in request

        resp = self.send(prep, **send_kwargs)

      File "C:\Users\<username>\AppData\Roaming\Python\Python36\site-packages\requests\sessions.py", line 618, in send

        r = adapter.send(request, **kwargs)

      File "C:\Users\Tlebeau\AppData\Roaming\Python\Python36\site-packages\requests\adapters.py", line 506, in send

        raise SSLError(e, request=request)

    requests.exceptions.SSLError: HTTPSConnectionPool(host='temp.powerfaids.org', port=443): Max retries exceeded with url: /api/2/ping/ (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)'),))

     

    During handling of the above exception, another exception occurred:

     

    Traceback (most recent call last):

      File "C:/Users/Tlebeau/Dropbox/Work Stuff/PyCharmProjects/TestPFAPI/SFTP API Test.py", line 4, in <module>

        pprint.pprint(api.get('/ping'))

      File "C:\Program Files (x86)\lib\site-packages\smartfile\__init__.py", line 125, in get

        return self._request('get', endpoint, id=id, params=kwargs)

      File "C:\Program Files (x86)\lib\site-packages\smartfile\__init__.py", line 110, in _request

        return self._do_request(request, url, **kwargs)

      File "C:\Program Files (x86)\lib\site-packages\smartfile\__init__.py", line 207, in _do_request

        return super(BasicClient, self)._do_request(*args, **kwargs)

      File "C:\Program Files (x86)\lib\site-packages\smartfile\__init__.py", line 55, in _do_request

        raise RequestError(e)

    smartfile.errors.RequestError: HTTPSConnectionPool(host='temp.powerfaids.org', port=443): Max retries exceeded with url: /api/2/ping/ (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)'),))

     

    Process finished with exit code 1

    Reply Like 1
Like Follow
  • 1 yr agoLast active
  • 5Replies
  • 218Views
  • 3 Following