davidteather/TikTok-Api

http.client.BadStatusLine

fratamico opened this issue · 4 comments

Thank you so much for this api! When running on my personal computer it runs fine, however when running on an AWS ubuntu server, I get the BadStatusLine error occasionally when hitting the api.bySound method. Any ideas what could be causing this? I'm running python 3.7.7 and am on the latest version of your TikTokAPI on my server.

The full error trace is below:

Traceback (most recent call last):
  File "src/get_video_by_song.py", line 26, in get_videos_by_song_id
    tiktoks = api.bySound(song_id, count)
  File "/home/ubuntu/.local/lib/python3.7/site-packages/TikTokApi/tiktok.py", line 92, in bySound
    b = browser(api_url)
  File "/home/ubuntu/.local/lib/python3.7/site-packages/TikTokApi/browser.py", line 27, in __init__
    asyncio.get_event_loop().run_until_complete(self.start())
  File "/usr/lib/python3.7/asyncio/base_events.py", line 587, in run_until_complete
    return future.result()
  File "/home/ubuntu/.local/lib/python3.7/site-packages/TikTokApi/browser.py", line 30, in start
    self.browser = await pyppeteer.launch(self.options)
  File "/home/ubuntu/.local/lib/python3.7/site-packages/pyppeteer/launcher.py", line 305, in launch
    return await Launcher(options, **kwargs).launch()
  File "/home/ubuntu/.local/lib/python3.7/site-packages/pyppeteer/launcher.py", line 166, in launch
    self.browserWSEndpoint = get_ws_endpoint(self.url)
  File "/home/ubuntu/.local/lib/python3.7/site-packages/pyppeteer/launcher.py", line 227, in get_ws_endpoint
    with urlopen(url) as f:
  File "/usr/lib/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.7/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/usr/lib/python3.7/urllib/request.py", line 543, in _open
    '_open', req)
  File "/usr/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.7/urllib/request.py", line 1347, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/lib/python3.7/urllib/request.py", line 1322, in do_open
    r = h.getresponse()
  File "/usr/lib/python3.7/http/client.py", line 1344, in getresponse
    response.begin()
  File "/usr/lib/python3.7/http/client.py", line 306, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.7/http/client.py", line 288, in _read_status
    raise BadStatusLine(line)
http.client.BadStatusLine: GET /json/version HTTP/1.1

One thing I would check is make sure the ubuntu firewall as well as your aws security policy allows for outgoing connections.

Another thing might be TikTok is doing spam protection against that data center if too many requests are being sent to their servers from the data center.

Here's a stackover flow that may help.

Thanks! It doesn't always error and seems to run faster on the server, so perhaps it is the TikTok spam detection. I'll try throttling it.

Just adding a time.sleep(30) each (rare) time that error occurred, then trying again seemed to fix it. Thanks again!

No problem glad I could help