appwrite / sdk-for-python

[READ-ONLY] Official Appwrite Python SDK 🐍
https://appwrite.io
BSD 3-Clause "New" or "Revised" License
226 stars 57 forks source link

🐛 Bug Report: library not working around `http` and only works for `https` #52

Closed hemangjoshi37a closed 1 year ago

hemangjoshi37a commented 1 year ago

👟 Reproduction steps

I run code :

users = Users(client)
result = users.create('uiduid123', 'email@example.com', 'password')
print(result)

it gives me this error :

---------------------------------------------------------------------------
gaierror                                  Traceback (most recent call last)
File /usr/lib/python3/dist-packages/urllib3/connection.py:174, in HTTPConnection._new_conn(self)
    173 try:
--> 174     conn = connection.create_connection(
    175         (self._dns_host, self.port), self.timeout, **extra_kw
    176     )
    178 except SocketTimeout:

File /usr/lib/python3/dist-packages/urllib3/util/connection.py:73, in create_connection(address, timeout, source_address, socket_options)
     69     return six.raise_from(
     70         LocationParseError("'%s', label empty or too long" % host), None
     71     )
---> 73 for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
     74     af, socktype, proto, canonname, sa = res

File /usr/lib/python3.11/socket.py:962, in getaddrinfo(host, port, family, type, proto, flags)
    961 addrlist = []
--> 962 for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    963     af, socktype, proto, canonname, sa = res

gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

NewConnectionError                        Traceback (most recent call last)
File /usr/lib/python3/dist-packages/urllib3/connectionpool.py:704, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    703 # Make the request on the httplib connection object.
--> 704 httplib_response = self._make_request(
    705     conn,
    706     method,
    707     url,
    708     timeout=timeout_obj,
    709     body=body,
    710     headers=headers,
    711     chunked=chunked,
    712 )
    714 # If we're going to release the connection in ``finally:``, then
    715 # the response doesn't need to know about the connection. Otherwise
    716 # it will also try to release it and we'll have a double-release
    717 # mess.

File /usr/lib/python3/dist-packages/urllib3/connectionpool.py:387, in HTTPConnectionPool._make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    386 try:
--> 387     self._validate_conn(conn)
    388 except (SocketTimeout, BaseSSLError) as e:
    389     # Py2 raises this as a BaseSSLError, Py3 raises it as socket timeout.

File /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1045, in HTTPSConnectionPool._validate_conn(self, conn)
   1044 if not getattr(conn, "sock", None):  # AppEngine might not have  `.sock`
-> 1045     conn.connect()
   1047 if not conn.is_verified:

File /usr/lib/python3/dist-packages/urllib3/connection.py:358, in HTTPSConnection.connect(self)
    356 def connect(self):
    357     # Add certificate verification
--> 358     self.sock = conn = self._new_conn()
    359     hostname = self.host

File /usr/lib/python3/dist-packages/urllib3/connection.py:186, in HTTPConnection._new_conn(self)
    185 except SocketError as e:
--> 186     raise NewConnectionError(
    187         self, "Failed to establish a new connection: %s" % e
    188     )
    190 return conn

NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7ff0702756d0>: Failed to establish a new connection: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

MaxRetryError                             Traceback (most recent call last)
File /usr/lib/python3/dist-packages/requests/adapters.py:489, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
    488 if not chunked:
--> 489     resp = conn.urlopen(
    490         method=request.method,
    491         url=url,
    492         body=request.body,
    493         headers=request.headers,
    494         redirect=False,
    495         assert_same_host=False,
    496         preload_content=False,
    497         decode_content=False,
    498         retries=self.max_retries,
    499         timeout=timeout,
    500     )
    502 # Send the request.
    503 else:

File /usr/lib/python3/dist-packages/urllib3/connectionpool.py:788, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    786     e = ProtocolError("Connection aborted.", e)
--> 788 retries = retries.increment(
    789     method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
    790 )
    791 retries.sleep()

File /usr/lib/python3/dist-packages/urllib3/util/retry.py:592, in Retry.increment(self, method, url, response, error, _pool, _stacktrace)
    591 if new_retry.is_exhausted():
--> 592     raise MaxRetryError(_pool, url, error or ResponseError(cause))
    594 log.debug("Incremented Retry for (url='%s'): %r", url, new_retry)

MaxRetryError: HTTPSConnectionPool(host='hostname', port=443): Max retries exceeded with url: /v1/users (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7ff0702756d0>: Failed to establish a new connection: [Errno -2] Name or service not known'))

During handling of the above exception, another exception occurred:

ConnectionError                           Traceback (most recent call last)
File ~/.local/lib/python3.11/site-packages/appwrite/client.py:86, in Client.call(self, method, path, headers, params)
     85 try:
---> 86     response = requests.request(  # call method dynamically https://stackoverflow.com/a/4246075/2299554
     87         method=method,
     88         url=self._endpoint + path,
     89         params=self.flatten(params, stringify=stringify),
     90         data=self.flatten(data),
     91         json=json,
     92         files=files,
     93         headers=headers,
     94         verify=(not self._self_signed),
     95     )
     97     response.raise_for_status()

File /usr/lib/python3/dist-packages/requests/api.py:59, in request(method, url, **kwargs)
     58 with sessions.Session() as session:
---> 59     return session.request(method=method, url=url, **kwargs)

File /usr/lib/python3/dist-packages/requests/sessions.py:587, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    586 send_kwargs.update(settings)
--> 587 resp = self.send(prep, **send_kwargs)
    589 return resp

File /usr/lib/python3/dist-packages/requests/sessions.py:701, in Session.send(self, request, **kwargs)
    700 # Send the request
--> 701 r = adapter.send(request, **kwargs)
    703 # Total elapsed time of the request (approximately)

File /usr/lib/python3/dist-packages/requests/adapters.py:565, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
    563         raise SSLError(e, request=request)
--> 565     raise ConnectionError(e, request=request)
    567 except ClosedPoolError as e:

ConnectionError: HTTPSConnectionPool(host='hostname', port=443): Max retries exceeded with url: /v1/users (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7ff0702756d0>: Failed to establish a new connection: [Errno -2] Name or service not known'))

During handling of the above exception, another exception occurred:

AppwriteException                         Traceback (most recent call last)
Cell In [4], line 2
      1 users = Users(client)
----> 2 result = users.create('uiduid123', 'email@example.com', 'password')
      3 result

File ~/.local/lib/python3.11/site-packages/appwrite/services/users.py:39, in Users.create(self, user_id, email, phone, password, name)
     36 params['password'] = password
     37 params['name'] = name
---> 39 return self.client.call('post', path, {
     40     'content-type': 'application/json',
     41 }, params)

File ~/.local/lib/python3.11/site-packages/appwrite/client.py:113, in Client.call(self, method, path, headers, params)
    111         raise AppwriteException(response.text, response.status_code)
    112 else:
--> 113     raise AppwriteException(e)

AppwriteException: HTTPSConnectionPool(host='hostname', port=443): Max retries exceeded with url: /v1/users (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7ff0702756d0>: Failed to establish a new connection: [Errno -2] Name or service not known'))

👍 Expected behavior

should make a new user

👎 Actual Behavior

not making a new user

🎲 Appwrite version

Version 0.10.x

💻 Operating system

Linux

🧱 Your Environment

no customization. verything standard and as latest as it can get.

👀 Have you spent some time to check if this issue has been raised before?

🏢 Have you read the Code of Conduct?

markusleh commented 1 year ago

Have you correctly set the endpoint before making the request? client.set_endpoint("http://yourappwritehost/v1")

There is no indication in the error that you would have set the endpoint to a http. The client is attempting a connection to a https endpoint as indicated by the HTTPSConnectionPool error.

hemangjoshi37a commented 1 year ago

@markusleh Actaully the issue is with this library itself. Here in this library the getters and setters are not correctly implemented. Which I have correctly implemented to set the API endpoint and other arguments in my forked repo : https://github.com/hemangjoshi37a/sdk-for-python for which I also have placed one pull request #53 . Please merge my PR to resolve this issue.

stnguyen90 commented 1 year ago

@hemangjoshi37a, as @markusleh asked, did you initialize the client properly by calling client.set_endpoint("http://yourappwritehost/v1")? Also, please make sure you have _APP_OPTIONS_FORCE_HTTPS disabled and there are no other HTTP to HTTPS redirects.

hemangjoshi37a commented 1 year ago

ok

stnguyen90 commented 1 year ago

@hemangjoshi37a, are you still seeing the error or can this issue be closed now?

stnguyen90 commented 1 year ago

@hemangjoshi37a, are you still having problems? Please keep in mind that I'll need to close this because of inactivity soon.