davidteather / TikTok-Api

The Unofficial TikTok API Wrapper In Python
https://davidteather.github.io/TikTok-Api
MIT License
4.85k stars 974 forks source link

[INSTALLATION] - Docker Installation ConnectionRefusedError: [Errno 111] Connection refused #883

Open Hy77 opened 2 years ago

Hy77 commented 2 years ago

Hi all, I'm new to Python, so if my problem statement is unclear, please let me know and I'll do my best to explain it thoroughly. Thank you for any assistance.

Describe the error

ERROR [5/5] RUN python -m playwright install

The buggy code

PS E:\Python_codes\TikTok-Api-master> docker build . -t tiktokapi:latest [+] Building 387.8s (9/9) FINISHED => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 32B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for mcr.microsoft.com/playwright:focal 0.0s => [1/5] FROM mcr.microsoft.com/playwright:focal 0.0s => [internal] load build context 0.0s => => transferring context: 12.35kB 0.0s => CACHED [2/5] RUN apt-get update && apt-get install -y python3-pip 0.0s => [3/5] COPY . . 0.0s => [4/5] RUN pip3 install TikTokApi 387.1s => ERROR [5/5] RUN python -m playwright install 0.5s

[5/5] RUN python -m playwright install:

9 0.530 /bin/sh: 1: python: not found


executor failed running [/bin/sh -c python -m playwright install]: exit code: 127

Error Trace (if any)

Put the error trace below if there's any error thrown.

# Error Trace Here

Desktop (please complete the following information):

Additional context

pip install TikTokApi & python -m playwright install both were working properly But when I'm trying to run "docker build . -t tiktokapi:latest", it seems like can not run RUN python -m playwright install" properly

Hy77 commented 2 years ago

I think there might be some issues with downloading playwright-1.21.0-py3-none-manylinux1_x86_64.whl But I believe I have already installed playwright by running "pip install playwright" "playwright install" "python -m playwright install"

[4/5] RUN pip3 install TikTokApi:

8 1.756 Collecting TikTokApi

8 3.060 Downloading TikTokApi-5.1.1.tar.gz (64 kB)

8 3.958 Collecting playwright

8 4.103 Downloading playwright-1.21.0-py3-none-manylinux1_x86_64.whl (33.4 MB)

8 207.8 ERROR: Exception:

8 207.8 Traceback (most recent call last):

8 207.8 File "/usr/share/python-wheels/urllib3-1.25.8-py2.py3-none-any.whl/urllib3/response.py", line 425, in _error_catcher

8 207.8 yield

Krisseck commented 2 years ago

Change python to python3 in Dockerfile to fix the issue

Hy77 commented 2 years ago

Change python to python3 in Dockerfile to fix the issue

Thank you for your response; it works!!! Thank you incredibly much. If you don't mind, I have another question... "docker run -v TikTokApi —rm tiktokapi:latest python3 your script.py" I'm not sure what I should replace with "your script.py," do I need to create something to replace it? If so, how should I write the code in that .py file? Thank you for your patienceeee!

I attempted to use the codes in the example file. However, it claims that no such file exists.

PS E:\Python_codes\TikTok-Api-master> docker run -v TikTokApi --rm tiktokapi:latest python3 user_example.py python3: can't open file 'user_example.py': [Errno 2] No such file or directory

PS E:\Python_codes\TikTok-Api-master> docker run -v TikTokApi --rm tiktokapi:latest python3 E:\Python_codes\TikTok-Api-master\examples\user _example.py python3: can't open file 'E:\Python_codes\TikTok-Api-master\examples\user_example.py': [Errno 2] No such file or directory

Hy77 commented 2 years ago

Change python to python3 in Dockerfile to fix the issue

Thank you for your response; it works!!! Thank you incredibly much. If you don't mind, I have another question... "docker run -v TikTokApi —rm tiktokapi:latest python3 your script.py" I'm not sure what I should replace with "your script.py," do I need to create something to replace it? If so, how should I write the code in that .py file? Thank you for your patienceeee!

I attempted to use the codes in the example file. However, it claims that no such file exists.

PS E:\Python_codes\TikTok-Api-master> docker run -v TikTokApi --rm tiktokapi:latest python3 user_example.py python3: can't open file 'user_example.py': [Errno 2] No such file or directory

PS E:\Python_codes\TikTok-Api-master> docker run -v TikTokApi --rm tiktokapi:latest python3 E:\Python_codes\TikTok-Api-master\examples\user _example.py python3: can't open file 'E:\Python_codes\TikTok-Api-master\examples\user_example.py': [Errno 2] No such file or directory

Because I created myScript.py before I created the container, that's why it says no such file. And I copy and paste the code from the example files into myScript.py. However, when I try to run it, I encounter the following bug:

`Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "/usr/local/lib/python3.8/dist-packages/urllib3/util/connection.py", line 95, in create_connection
    raise err
  File "/usr/local/lib/python3.8/dist-packages/urllib3/util/connection.py", line 85, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.8/dist-packages/urllib3/connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.8/dist-packages/urllib3/connectionpool.py", line 1040, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.8/dist-packages/urllib3/connection.py", line 358, in connect
    self.sock = conn = self._new_conn()
  File "/usr/local/lib/python3.8/dist-packages/urllib3/connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7fd31053c850>: Failed to establish a new connection:
 [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/requests/adapters.py", line 440, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.8/dist-packages/urllib3/connectionpool.py", line 785, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.8/dist-packages/urllib3/util/retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.tiktok.com', port=443): Max retries exceeded with url: / (Caused by NewConn
ectionError('<urllib3.connection.HTTPSConnection object at 0x7fd31053c850>: Failed to establish a new connection: [Errno 111] Connection re
fused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "myScript.py", line 5, in <module>
    for video in api.trending.videos():
  File "/TikTokApi/api/trending.py", line 35, in videos
    spawn = requests.head(
  File "/usr/local/lib/python3.8/dist-packages/requests/api.py", line 102, in head
    return request('head', url, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/requests/sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.8/dist-packages/requests/sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/requests/adapters.py", line 519, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='www.tiktok.com', port=443): Max retries exceeded with url: / (Caused by NewC
onnectionError('<urllib3.connection.HTTPSConnection object at 0x7fd31053c850>: Failed to establish a new connection: [Errno 111] Connection
 refused'))`   

Thanks for any help