davidteather / TikTok-Api

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

[BUG] - SSL: CERTIFICATE_VERIFY_FAILED #621

Closed Juan-Rivera closed 3 years ago

Juan-Rivera commented 3 years ago

Describe the bug

Receiving SSL: CERTIFICATE_VERIFY_FAILED when using proxies.

The buggy code

def check_views(username):

    # api config
    verifyFp='...'
    api = TikTokApi.get_instance(proxy=super_proxy_url, custom_verifyFp=verifyFp)

    # how many videos to analyze
    n_videos = 9
    # fetching for vids
    user_videos = api.byUsername(username, count=n_videos, custom_verifyFp=verifyFp, proxy=super_proxy_url)

    results = []
    view_check = False

    for vid in user_videos:
        vc = vid['stats']['playCount']
        if vc > 15000:
            results.append(vc)

    if len(results) > 4:
        view_check = True

    return view_check

check_views('tiktok')

Expected behavior

Request for users videos should be going through and I would be getting either True or False on whether the check_views function passed

Error Trace (if any)

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

requests.exceptions.SSLError: HTTPSConnectionPool(host='tiktok.com', port=443): Max retries exceeded with url: /@tiktok?lang=en (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')))

Desktop (please complete the following information):

dylancaponi commented 3 years ago

You must add requests_extra_kwargs={"verify": False} to your TikTokApi.get_instance()

eg.

api = TikTokApi.get_instance(proxy=super_proxy_url, custom_verifyFp=verifyFp, requests_extra_kwargs={"verify": False})