Vaelor / python-mattermost-driver

Python Mattermost Driver for APIv4
https://vaelor.github.io/python-mattermost-driver/
MIT License
189 stars 69 forks source link

Not able to authenticate while using Personal Access Token #65

Closed IronVenom closed 4 years ago

IronVenom commented 4 years ago
Traceback (most recent call last):
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\urllib3\connection.py", line 141, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\urllib3\util\connection.py", line 60, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "C:\Users\ATHARVA\Anaconda3\lib\socket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 345, in _make_request
    self._validate_conn(conn)
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 844, in _validate_conn
    conn.connect()
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\urllib3\connection.py", line 284, in connect
    conn = self._new_conn()
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\urllib3\connection.py", line 150, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x000002C648DF85F8>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\requests\adapters.py", line 449, in send
    timeout=timeout
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 649, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\urllib3\util\retry.py", line 388, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='https', port=443): Max retries exceeded with url: //bot-dev-hackathon-iitbbs.herokuapp.com:8065/api/v4/users/me (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x000002C648DF85F8>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "mattermostdevbot.py", line 14, in <module>
    driver.login()
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\mattermostdriver\driver.py", line 162, in login
    result = self.users.get_user('me')
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\mattermostdriver\endpoints\users.py", line 45, in get_user
    self.endpoint + '/' + user_id
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\mattermostdriver\client.py", line 193, in get
    response = self.make_request('get', endpoint, options=options, params=params)
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\mattermostdriver\client.py", line 159, in make_request
    **request_params
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\requests\adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='https', port=443): Max retries exceeded with url: //bot-dev-hackathon-iitbbs.herokuapp.com:8065/api/v4/users/me (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x000002C648DF85F8>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',))

I am getting the above error whenever I am trying to authenticate my bot.

This is the code that I am running :

from mattermostdriver import Driver

driver_options = {
        'url': "url",
        'token':'token',
        'scheme': 'https',
        'port': 8065,
        'basepath': '/api/v4',
        'verify': True
    }
driver = Driver(driver_options)

print("Authenticating...")
driver.login()
print("Successfully authenticated.")
IronVenom commented 4 years ago
from mattermostdriver import Driver

driver_options = {
        'url': "url",
        'token':'token'
}

driver = Driver(driver_options)

print("Authenticating...")
driver.login()
print("Successfully authenticated.")

This code is giving me the following errors :

Traceback (most recent call last):
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\urllib3\util\connection.py", line 73, in create_connection
    sock.connect(sa)
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
artempronevskiy commented 4 years ago
Max retries exceeded with url: //bot-dev-hackathon-iitbbs.herokuapp.com:8065/api/v4/users/me (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x000002C648DF85F8>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',))

Please check your URL. I'm not sure this one is correct:

//bot-dev-hackathon-iitbbs.herokuapp.com:8065/api/v4/users/me 

protocol (http/https) is missing.

IronVenom commented 4 years ago

@artempronevskiy Its still not working.

artempronevskiy commented 4 years ago

@IronVenom share new stacktrace

IronVenom commented 4 years ago
Authenticating...
Traceback (most recent call last):
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\urllib3\connection.py", line 141, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\urllib3\util\connection.py", line 60, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "C:\Users\ATHARVA\Anaconda3\lib\socket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 345, in _make_request
    self._validate_conn(conn)
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 844, in _validate_conn
    conn.connect()
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\urllib3\connection.py", line 284, in connect
    conn = self._new_conn()
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\urllib3\connection.py", line 150, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x0000026F06B98588>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\requests\adapters.py", line 449, in send
    timeout=timeout
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 649, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\urllib3\util\retry.py", line 388, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='https', port=443): Max retries exceeded with url: //bot-dev-hackathon-iitbbs.herokuapp.com:8065/api/v4/users/me:443/api/v4/users/me (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x0000026F06B98588>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "mattermostdevbot.py", line 12, in <module>
    driver.login()
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\mattermostdriver\driver.py", line 162, in login
    result = self.users.get_user('me')
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\mattermostdriver\endpoints\users.py", line 45, in get_user
    self.endpoint + '/' + user_id
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\mattermostdriver\client.py", line 193, in get
    response = self.make_request('get', endpoint, options=options, params=params)
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\mattermostdriver\client.py", line 159, in make_request
    **request_params
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\ATHARVA\Anaconda3\lib\site-packages\requests\adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='https', port=443): Max retries exceeded with url: //bot-dev-hackathon-iitbbs.herokuapp.com:8065/api/v4/users/me:443/api/v4/users/me (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x0000026F06B98588>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',))
artempronevskiy commented 4 years ago

@IronVenom Check if your app is available via that port. I'm not able to establish TCP connection to bot-dev-hackathon-iitbbs.herokuapp.com via 8065 port:

$ telnet bot-dev-hackathon-iitbbs.herokuapp.com 8065
Trying 34.200.167.100...
IronVenom commented 4 years ago

This is my code:

from mattermostdriver import Driver

driver_options = {
        'url': "https://bot-dev-hackathon-iitbbs.herokuapp.com",
        'token':'token',
}

driver = Driver(driver_options)

print("Authenticating...")
driver.login()
print("Successfully authenticated.")

I am using a Personal Access Token to authenticate the connection. Its according to the documentation, and the app is working.

IronVenom commented 4 years ago

Are there any reasons that this is happening? Because I am doing everything according to the Mattermost API docs and mattermost driver docs

IronVenom commented 4 years ago

So basically, the bot is making the request correctly, its reaching Mattermost, and then its getting denied. Do I have to make any changes in the settings of the server?

rashad commented 4 years ago

Quick up, what was the issue ? 👀