appwrite / playground-for-python

Simple examples that help you get started with Appwrite + Python (=❤️)
https://appwrite.io
MIT License
65 stars 51 forks source link

🐛 Bug Report: Error while interacting with `database` #55

Closed hemangjoshi37a closed 4 months ago

hemangjoshi37a commented 1 year ago

👟 Reproduction steps

Running Create Database API
---------------------------------------------------------------------------
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 0x7fc7358c6850>: 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/databases (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fc7358c6850>: 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/databases (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fc7358c6850>: 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 325
    322     delete_function()
    324 if __name__ == "__main__":
--> 325     run_all_tasks()
    326     p("Successfully ran playground!")

Cell In [4], line 296, in run_all_tasks()
    293 def run_all_tasks():
    294 
    295     # Databases
--> 296     create_database()
    297     create_collection()
    298     list_collections()

Cell In [4], line 46, in create_database()
     43 global database_id
     45 p("Running Create Database API")
---> 46 response = databases.create(
     47     database_id=ID.unique(),
     48     name='Movies',
     49 )
     50 database_id = response['$id']
     51 print(response)

File ~/.local/lib/python3.11/site-packages/appwrite/services/databases.py:39, in Databases.create(self, database_id, name)
     36 params['databaseId'] = database_id
     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/databases (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fc7358c6850>: Failed to establish a new connection: [Errno -2] Name or service not known'))

👍 Expected behavior

should work

👎 Actual Behavior

not working

🎲 Appwrite version

Version 0.10.x

💻 Operating system

Linux

🧱 Your Environment

everything latest and standard

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

🏢 Have you read the Code of Conduct?

joeyouss commented 1 year ago

Hi @hemangjoshi37a , this repo is pretty outdated and that is why you must be facing these errors.

stnguyen90 commented 5 months ago

Closing stale issue

hemangjoshi37a commented 5 months ago

tell me one thing mr @stnguyen90 why are you so keen on closing the issue even if it has not been resolved ? how would anyone know that this issue even exists if you close without solving it. stale or non-stale a issue is only closed when it is solved simply even if it takes 10 or 15 or 50 years to solve it . what happiness you get when closing ongoing issues?

stnguyen90 commented 5 months ago

@hemangjoshi37a, I'm more than happy to reopen this if you still need help troubleshooting.

Looking at the error, it seems the hostname may be incorrect or not set. What did you set for the appwrite endpoint and project id? Did you set an API key?

https://github.com/appwrite/playground-for-python/blob/64eef9bb05ed5d02f4d169594bd87e47693eeb86/playground.py#L22-L25

stnguyen90 commented 4 months ago

Closing due to inactivity.