Brodan/patter

While piping errors

Closed this issue · 6 comments

➜ Documents pip install patter
Collecting patter
Downloading https://files.pythonhosted.org/packages/3e/86/eea5f3b98e8c2598daaf1c8e87d5a1e2f1930b9f1301be797194d0b8680a/patter-0.1.0.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/private/var/folders/vk/6d2cgfk965sc6q8mc73886_80000gn/T/pip-install-9N3esq/patter/setup.py", line 6, in
with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
TypeError: 'encoding' is an invalid keyword argument for this function

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/vk/6d2cgfk965sc6q8mc73886_80000gn/T/pip-install-9N3esq/patter/
➜ Documents pip install patter

I managed to fix this issue with pip3 install patter .

`Revenger:patter cosmicsound$ echo "testing" | patter -c town-square
Unable to connect to the configured Mattermost server.
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connection.py", line 171, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/util/connection.py", line 56, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 748, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 849, in _validate_conn
conn.connect()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connection.py", line 314, in connect
conn = self._new_conn()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connection.py", line 180, in _new_conn
self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x10221a9e8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/adapters.py", line 445, in send
timeout=timeout
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/util/retry.py", line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='https', port=443): Max retries exceeded with url: //chat.uhlhosting.ch:8065/api/v4/users/login (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x10221a9e8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/bin/patter", line 40, in
patter = Patter(sys.stdin.read(), args.p, args.user, args.channel, args.verbose)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/patter/patter.py", line 44, in init
self.mm_client.login()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mattermostdriver/driver.py", line 158, in login
'token': self.options['mfa_token']
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mattermostdriver/endpoints/users.py", line 8, in login_user
return self.client.make_request('post', self.endpoint + '/login', options)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mattermostdriver/client.py", line 137, in make_request
files=files
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/api.py", line 112, in post
return request('post', url, data=data, json=json, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/sessions.py", line 512, in request
resp = self.send(prep, **send_kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/sessions.py", line 622, in send
r = adapter.send(request, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/adapters.py", line 513, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='https', port=443): Max retries exceeded with url: //chat.uhlhosting.ch:8065/api/v4/users/login (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x10221a9e8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))
Revenger:patter cosmicsound$
`

Hey @uhlhosting, this is some kind of error with your configuration. Unfortunately, since any number of things can go wrong when connecting to the Mattermost server, it's tough to pinpoint exactly which thing is misconfigured.

My guess would be the MATTERMOST_PORT environment variable is incorrect since it looks like your Mattermost is sitting behind HTTPS. This tripped me up initially too when I was testing on my company's Mattermost server. Try setting it to 443 (assuming you have it set to 8065).

Let me know if that works!

Hi @Brodan

I have had played before with the port, it seems nothing really helped.

This is my current config in ~/.bash_profile

export MATTERMOST_TEAM_NAME="DevOps"
export MATTERMOST_URL="https://chat.uhlhosting.ch"
export MATTERMOST_USERNAME="xxxxxxxxxxxx"
export MATTERMOST_PASSWORD="xxxxxxxxxxxx"
export MATTERMOST_PORT="443"

Revenger:~ cosmicsound$ echo "testing" | patter -c town-square
Unable to connect to the configured Mattermost server.
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connection.py", line 171, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/util/connection.py", line 56, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 748, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 849, in _validate_conn
    conn.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connection.py", line 314, in connect
    conn = self._new_conn()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connection.py", line 180, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x10ec6dac8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/adapters.py", line 445, in send
    timeout=timeout
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/util/retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='https', port=443): Max retries exceeded with url: //chat.uhlhosting.ch:443/api/v4/users/login (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x10ec6dac8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/bin/patter", line 40, in <module>
    patter = Patter(sys.stdin.read(), args.p, args.user, args.channel, args.verbose)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/patter/patter.py", line 44, in __init__
    self.mm_client.login()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mattermostdriver/driver.py", line 158, in login
    'token': self.options['mfa_token']
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mattermostdriver/endpoints/users.py", line 8, in login_user
    return self.client.make_request('post', self.endpoint + '/login', options)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mattermostdriver/client.py", line 137, in make_request
    files=files
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/api.py", line 112, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/sessions.py", line 512, in request
    resp = self.send(prep, **send_kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/sessions.py", line 622, in send
    r = adapter.send(request, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/adapters.py", line 513, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='https', port=443): Max retries exceeded with url: //chat.uhlhosting.ch:443/api/v4/users/login (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x10ec6dac8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))
Revenger:~ cosmicsound$ 

The only thing I can think of is that a HTTPS protocol does not explicitl need port especially when using the link:

The process starts to go to https://chat.uhlhosting.ch:443/api/v4/users/login

I think it should result in
https://chat.uhlhosting.ch/api/v4/users/login

id "api.context.session_expired.app_error"
message "Invalid or expired session, please login again."
detailed_error "UserRequired"
request_id "kw3fcmod5igpmp56mqg5xizb4w"
status_code 401

Hey @uhlhosting, I just had a co-worker run into something similar. I think the MATTERMOST_URL needs to exclude the https://, so in your case you would use export MATTERMOST_URL="chat.uhlhosting.ch". Also, the MATTERMOST_USERNAME should be your full email address login, which is super annoying I know. I'll look into fixing/updating this.

image

Thanks, now works!