dfreelon / pyktok

A simple module to collect video, text, and metadata from Tiktok.
BSD 3-Clause "New" or "Revised" License
316 stars 44 forks source link

Error opening Cookies.binarycookies #20

Closed dphiffer closed 1 year ago

dphiffer commented 1 year ago

I tried running this test from the README, in a new Python 3.9 virtual environment:

import pyktok as pyk

pyk.save_tiktok('https://www.tiktok.com/@tiktok/video/7106594312292453675?is_copy_url=1&is_from_webapp=v1',
        True,
        'video_data.csv',
        'chrome')

I got a series of macOS password prompts and then this error: PermissionError: [Errno 1] Operation not permitted: '/Users/dphiffer/Library/Containers/com.apple.Safari/Data/Library/Cookies/Cookies.binarycookies'

The permissions on that file are 644, owned by me. I wonder if macOS is doing something to prevent reading my cookies? I also wonder if I could configure a separate cookie store from (what appears to be) my Safari.app cookies?

Here's the full stack trace:

$ python test.py
Traceback (most recent call last):
  File "/Users/dphiffer/Projects/pyktok/test.py", line 1, in <module>
    import pyktok as pyk
  File "/Users/dphiffer/Projects/pyktok/env/lib/python3.9/site-packages/pyktok/__init__.py", line 1, in <module>
    from .pyktok import *
  File "/Users/dphiffer/Projects/pyktok/env/lib/python3.9/site-packages/pyktok/pyktok.py", line 40, in <module>
    cookies = browser_cookie3.load()
  File "/Users/dphiffer/Projects/pyktok/env/lib/python3.9/site-packages/browser_cookie3/__init__.py", line 987, in load
    for cookie in cookie_fn(domain_name=domain_name):
  File "/Users/dphiffer/Projects/pyktok/env/lib/python3.9/site-packages/browser_cookie3/__init__.py", line 978, in safari
    return Safari(cookie_file, domain_name).load()
  File "/Users/dphiffer/Projects/pyktok/env/lib/python3.9/site-packages/browser_cookie3/__init__.py", line 812, in __init__
    self.__open_file(cookie_file)
  File "/Users/dphiffer/Projects/pyktok/env/lib/python3.9/site-packages/browser_cookie3/__init__.py", line 823, in __open_file
    self.__buffer = open(cookie_file, 'rb')
PermissionError: [Errno 1] Operation not permitted: '/Users/dphiffer/Library/Containers/com.apple.Safari/Data/Library/Cookies/Cookies.binarycookies'
dfreelon commented 1 year ago

I had a student with a similar problem and the following worked for her:

Hi, you can try to implement the top solution from this question: https://stackoverflow.com/questions/58479686/permissionerror-errno-1-operation-not-permitted-after-macos-catalina-update

But instead of Terminal, grant permissions for Python and/or whatever IDE you're using.

dphiffer commented 1 year ago

Thanks, that seemed to do the trick. I also upgraded my version of Python to get around a different problem: https://stackoverflow.com/questions/73530174/streamlit-protocols-cannot-be-instantiated