Code Monkey home page Code Monkey logo

akinator.py's Introduction

akinator.py

license lines of code PyPI version info

Python version info

Installing

To install the regular library without asynchronous support, just run the following command:

# Unix / macOS
python3 -m pip install "akinator"

# Windows
py -m pip install "akinator"

Otherwise, to get asynchronous support, do:

# Unix / macOS
python3 -m pip install "akinator[async]"

# Windows
py -m pip install "akinator[async]"

To get async support plus faster performance (via the aiodns and cchardet libraries), do:

# Unix / macOS
python3 -m pip install "akinator[fast_async]"

# Windows
py -m pip install "akinator[fast_async]"

To install the development version, do the following:

git clone https://github.com/Infiniticity/akinator.py

Requirements

Usually pip will handle these for you.

Links

akinator.py's People

Contributors

advnpzn avatar dependabot[bot] avatar ombucha avatar sravan1946 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

akinator.py's Issues

SSLCertificate Error(s)

Summary

Various SSL Certificate Error occurs when connecting to en.akinator.com

Reproduction Steps

For reproducing the error.
First,

pip install akinator

Then create a python file with the following, lets call it temp.py

from akinator import Akinator

a = Akinator()
a.start_game()

Then run the temp.py file.

python temp.py

This reproduction step was done on ubuntu both on my local machine using wsl and on a remote server (aws instance).
Used the latest akinator.py.

Minimal Reproducible Code

No response

Expected Results

The expected result would not show that SSL Error and normally it would return an Akinator Object or String i.e the question.

Actual Results

Traceback (most recent call last):
  File "/home/mito/Akinator-Bot/venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 467, in _make_request
    self._validate_conn(conn)
  File "/home/mito/Akinator-Bot/venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 1092, in _validate_conn
    conn.connect()
  File "/home/mito/Akinator-Bot/venv/lib/python3.10/site-packages/urllib3/connection.py", line 635, in connect
    sock_and_verified = _ssl_wrap_socket_and_match_hostname(
  File "/home/mito/Akinator-Bot/venv/lib/python3.10/site-packages/urllib3/connection.py", line 774, in _ssl_wrap_socket_and_match_hostname
    ssl_sock = ssl_wrap_socket(
  File "/home/mito/Akinator-Bot/venv/lib/python3.10/site-packages/urllib3/util/ssl_.py", line 459, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
  File "/home/mito/Akinator-Bot/venv/lib/python3.10/site-packages/urllib3/util/ssl_.py", line 503, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/lib/python3.10/ssl.py", line 513, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/lib/python3.10/ssl.py", line 1071, in _create
    self.do_handshake()
  File "/usr/lib/python3.10/ssl.py", line 1342, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/mito/Akinator-Bot/venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 790, in urlopen
    response = self._make_request(
  File "/home/mito/Akinator-Bot/venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 491, in _make_request
    raise new_e
urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/mito/Akinator-Bot/venv/lib/python3.10/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
  File "/home/mito/Akinator-Bot/venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 844, in urlopen
    retries = retries.increment(
  File "/home/mito/Akinator-Bot/venv/lib/python3.10/site-packages/urllib3/util/retry.py", line 515, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='en.akinator.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/mito/Akinator-Bot/temp.py", line 5, in <module>
    a.start_game()
  File "/home/mito/Akinator-Bot/venv/lib/python3.10/site-packages/akinator/akinator.py", line 160, in start_game
    region_info = self._auto_get_region(get_lang_and_theme(language)["lang"], get_lang_and_theme(language)["theme"])
  File "/home/mito/Akinator-Bot/venv/lib/python3.10/site-packages/akinator/akinator.py", line 112, in _auto_get_region
    r = requests.get("https://" + uri)
  File "/home/mito/Akinator-Bot/venv/lib/python3.10/site-packages/requests/api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
  File "/home/mito/Akinator-Bot/venv/lib/python3.10/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/mito/Akinator-Bot/venv/lib/python3.10/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/mito/Akinator-Bot/venv/lib/python3.10/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/home/mito/Akinator-Bot/venv/lib/python3.10/site-packages/requests/adapters.py", line 517, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='en.akinator.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))```

### System Information

wsl2
-----------------------------

OS : `Ubuntu 22.04.2 LTS`
Python: `Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux`
akinator version: `akinator 1.0.3`


AWS Instance
-----------------------------
OS : `Ubuntu 22.04.2 LTS`
Python: `Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux`
akinator version: `akinator 1.0.3`

### Checklist

- [X] I have searched open issues for duplicates.
- [X] I have shown the entire traceback, if possible.
- [X] I have made sure that this issue is valid.

### Additional Context

I was able to solve these errors by including `verify=False` in `requests.get()` for all requests in `akinator.py`.
Suppose if we have something like,

```python
r = requests.get("https://en.akinator.com/game")

Then adding verify=False will solve the issue, but it will throw a warning while the program is running.

r = requests.get("https://en.akinator.com/game", verify=False)

Encountered an error while using aki. start_game

Summary

Encountered an error while using aki. start_game

Reproduction Steps

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/aiohttp/web_protocol.py", line 452, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.9/dist-packages/aiohttp/web_app.py", line 543, in _handle
    resp = await handler(request)
  File "/app/app.py", line 48, in handle_request
    q = await aki.start_game(language=lang)
  File "/usr/local/lib/python3.9/dist-packages/akinator/async_aki/async_akinator.py", line 168, in start_game
    region_info = await self._auto_get_region(get_lang_and_theme(language)["lang"], get_lang_and_theme(language)["theme"])
  File "/usr/local/lib/python3.9/dist-packages/akinator/async_aki/async_akinator.py", line 114, in _auto_get_region
    parsed = json.loads(match.group().split("'arrUrlThemesToPlay', ")[-1])
AttributeError: 'NoneType' object has no attribute 'group'
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f819fc90670>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7f819fa81a60>, 5245086.969)]']
connector: <aiohttp.connector.TCPConnector object at 0x7f819fc905e0>

Minimal Reproducible Code

The problem can be reproduced 100% by only allowing the code in [ examples/async_aki.py ] to be run.
I'm pretty sure that the first time this error would have occurred would have been within five minutes before UTC/GMT: 2024-04-02 06:10:00 , and I think it's likely that akinator officially, probably at 6:00, changed something.

Expected Results

No errors

Actual Results

An error has occurred

System Information

Ubuntu 20.04.5 LTS (GNU/Linux 5.4.0-28-generic x86_64)

Checklist

  • I have searched open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have made sure that this issue is valid.

Additional Context

No response

Connect call Failed

Summary

When using asynchronous Akinator, it wont connect to en.akinator.com

Reproduction Steps

I followed the example https://github.com/Infiniticity/akinator.py/blob/main/examples/async_aki.py,
by adding the lib code into my own files, but async_aki is fetched from this repo itself...

Minimal Reproducible Code

Cannot connect to host en.akinator.com:443 ssl:default [Connect call failed ('2600:1f11:f39:6f3f:ad82:13e1:7fed:7818', 443, 0, 0)]

Expected Results

It was expected to post an embedded akinator game into discord...
image

Actual Results

it just fails..., with the error:

Cannot connect to host en.akinator.com:443 ssl:default [Connect call failed ('2600:1f11:f39:6f3f:ad82:13e1:7fed:7818', 443, 0, 0)]

image

System Information

It runs on a pterodactyl hosting service

Checklist

  • I have searched open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have made sure that this issue is valid.

Additional Context

For context of this issue, i have been implementing it in a discord bot.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.