jmjeon94 / N2T

Notion에서 Tistory로 포스팅을 해줍니다.
148 stars 47 forks source link

NameError: name 'token_v2' is not defined #24

Open YoungJ-Baek opened 1 year ago

YoungJ-Baek commented 1 year ago

Error

Notion 토큰 값을 정확히 기입했지만, 아래와 같이 token_v2가 정의되지 않았다고 나오는 현상

[2023_0709_093333]
Traceback (most recent call last):
  File "/Users/youngjin/Desktop/Dev_web/N2T/clients/NotionClient.py", line 13, in __init__
    self.client = NotionClient(token_v2=notion_token)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/youngjin/Desktop/Dev_web/N2T/N2T/lib/python3.11/site-packages/notion/client.py", line 77, in __init__
    self.session = create_session(client_specified_retry)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/youngjin/Desktop/Dev_web/N2T/N2T/lib/python3.11/site-packages/notion/client.py", line 39, in create_session
    retry = Retry(
            ^^^^^^
TypeError: Retry.__init__() got an unexpected keyword argument 'method_whitelist'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/youngjin/Desktop/Dev_web/N2T/main.py", line 168, in <module>
    client = Notion2Tistory(cfg, sleep_time=5, selenium_debug=False)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/youngjin/Desktop/Dev_web/N2T/main.py", line 25, in __init__
    self.n_client = Notion(cfg.NOTION.TOKEN_V2)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/youngjin/Desktop/Dev_web/N2T/clients/NotionClient.py", line 17, in __init__
    raise ValueError('[Error] notion token값이 올바르지 않습니다. 다시 확인 해 주세요. [{}]'.format(token_v2))
                                                                                  ^^^^^^^^
NameError: name 'token_v2' is not defined

Solution

토큰 문제가 아닌 method_whitelist feature의 문제이며, 이는 urllib3 라이브러리 업데이트로 feature가 변경되었기 때문으로 보입니다. 해당 feature가 사용되는 notion 라이브러리에서 아래와 같이 수정해주면 토큰이 정확한 경우 문제 없이 진행하실 수 있습니다. 위치: ~/lib/python3.11/site-packages/notion/client.py 수정: method_whitelist=(...)allowed_methods=(...),

YoungJ-Baek commented 1 year ago

Reference 페이지 추가합니다.

https://github.com/jamalex/notion-py/issues/386