본문 바로가기
python

[N2T] N2T 노션 토큰 오류 해결

by ohojee 2023. 9. 25.
2023_0921_123614]
Traceback (most recent call last):
  File "/Users/jooheekim/Desktop/N2T/clients/NotionClient.py", line 13, in __init__
    self.client = NotionClient(token_v2=notion_token)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/notion/client.py", line 77, in __init__
    self.session = create_session(client_specified_retry)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/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/jooheekim/Desktop/N2T/main.py", line 168, in <module>
    client = Notion2Tistory(cfg, sleep_time=5, selenium_debug=False)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jooheekim/Desktop/N2T/main.py", line 25, in __init__
    self.n_client = Notion(cfg.NOTION.TOKEN_V2)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jooheekim/Desktop/N2T/clients/NotionClient.py", line 17, in __init__
    raise ValueError('[Error] notion token값이 올바르지 않습니다. 다시 확인 해 주세요. [{}]'.format(notion_token))
ValueError: [Error] notion token값이 올바르지 않습니다. 다시 확인 해 주세요. [v02%3Auser_token_or_cookies%3ATRUIeCoiBLf6jLA3VCmivROIsSqEnIDVqy0B-DyglAHUgu8ivZIoYkQNcojP4lOQdDXj1Za0DI09oqn3QpivWIWvO7Vx2sP26cbK6rn3LWh_AT_eevs_7oDNxQnGZwsOp09D]

[완료] 프로그램 종료.

저번에도 계속 이렇게 노션 토큰 오류가 발생했는데 해결방법도 못 찾겠어서 하,, 그냥 내가 복사해서 올리고 말지. 하면서 포기했었다.

근데 얼마 전에 다시 실행해보니 urllib3 라이브러리 업데이트로 인해 생긴 오류라고 한다. 전에도 whitelist를 검색해봤던 것 같긴한데 그 때는 뭘 해도 해결 방법이 뜨지 않았다.

/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/notion/client.py

전체적인 경로는 다를 수 있다. notion 패키지 안의 client.py에서 사용된

method_whitelist allowed_methods로 바꿔주면 된다.

 

 

참고 자료

https://github.com/jmjeon94/N2T/issues/24

 

NameError: name 'token_v2' is not defined · Issue #24 · jmjeon94/N2T

Error Notion 토큰 값을 정확히 기입했지만, 아래와 같이 token_v2가 정의되지 않았다고 나오는 현상 [2023_0709_093333] Traceback (most recent call last): File "/Users/youngjin/Desktop/Dev_web/N2T/clients/NotionClient.py", line 13,

github.com

 


이러면 될 줄 알았는데, , ,

또 다른 오류가 발생했다.

Error getting version of chromedriver 116. Retrying with chromedriver 115 (attempt 1/5)
Error getting version of chromedriver 115. Retrying with chromedriver 114 (attempt 2/5)
File "/Users/jooheekim/Desktop/N2T/clients/SeleniumClient.py", line 30, in __init__
    ChromeDriverManager().install(), options=options
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// ...
raise ValueError(f"There is no such driver by url {resp.url}")
ValueError: There is no such driver by url https://chromedriver.storage.googleapis.com/LATEST_RELEASE_116.0.5845
selenium.common.exceptions.SessionNotCreatedException: This version of ChromeDriver only supports Chrome version 114. LATEST_RELEASE_115 doesn't exist

읽어보니 크롬 버전이 업데이트 되어 다들 아래와 같이 설치 시에 버전을 설정해줘서 114버전으로 사용하고 있었다.

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)

 

참고자료

https://www.inflearn.com/questions/949511/%EC%85%80%EB%A0%88%EB%8B%88%EC%9B%80-%EC%A0%95%EC%83%81-%EC%9E%91%EB%8F%99-%EB%90%98%EB%8B%A4%EA%B0%80-%EC%98%A4%EB%8A%98%EB%B6%80%EB%A1%9C-%EA%B0%91%EC%9E%90%EA%B8%B0-%EC%98%A4%EB%A5%98%EA%B0%80-%EB%B0%9C%EC%83%9D

 

셀레니움 정상 작동 되다가 오늘부로 갑자기 오류가 발생 - 인프런 | 질문 & 답변

안녕하세요. 강의를 잘 수강하고 있습니다.다름이 아니라 셀레니움으로 작성했던 코드들이 정상적으로 모두 잘 작동되다가 오늘부로 갑자기 오류가 발생하여 문의드립니다!오류를 해결하기 위

www.inflearn.com


TypeError: WebDriver.__init__() got multiple values for argument 'options'

이러한 오류도 떠서 다시 찾아보니 

service = Service()

이걸로 해주고 selenium을 업데이트 해주면 된다.

결국 최종 수정한 코드는 아래와 같다.

from selenium import webdriver
// ...
service = Service()
options = webdriver.ChromeOptions()
// ...
try:
    self.driver = webdriver.Chrome(
        service=service, options=options
	)
// ...

 

 

참고자료

https://stackoverflow.com/questions/76913935/selenium-common-exceptions-sessionnotcreatedexception-this-version-of-chromedri

 

selenium.common.exceptions.SessionNotCreatedException: This version of ChromeDriver only supports Chrome version 114. LATEST_REL

#Once the zip has finished downloading, extract the folder and copy the path of the chromedriver exe file (should be the #first one), add it to your code like this, from selenium import webdriver ...

stackoverflow.com


오류의 연속, , ,, 행복해라, , ,,

그 다음 뜬 오류는 아래와 같다.

code = soup.script.text.split('code=')[1].split('&state')[0]
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/jooheekim/Desktop/N2T/main.py", line 168, in <module>
    client = Notion2Tistory(cfg, sleep_time=5, selenium_debug=False)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jooheekim/Desktop/N2T/main.py", line 56, in __init__
    authorize_code = self.s_client.get_tistory_authorize_code(cfg.TISTORY.CLIENT_ID, cfg.TISTORY.REDIRECT_URI)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jooheekim/Desktop/N2T/clients/SeleniumClient.py", line 118, in get_tistory_authorize_code
    raise ValueError(f'[Error] Tistory 인증 코드 발급 실패. 위의 출력 메시지를 보고 로그인이 되어있는지 확인해주세요.')
ValueError: [Error] Tistory 인증 코드 발급 실패. 위의 출력 메시지를 보고 로그인이 되어있는지 확인해주세요.

그래서 n2t사용 방법이 올라온 댓글과 깃허브 issue를 보니 나와 같은 사람들이 많았다. 그 중

print('0.',authorize_url)

이걸 출력해보고 이 링크를 열었을 때 아래와 같은 페이지가 아니라 블로그홈이 나오면 다른 문제가 있다는 거였다. 

아래와 같이 뜬다면 redirect url에 /이 빠졌거나 client id가 잘못된 상태일 거라고 한다.

이 페이지에서 허가하기를 눌러주면 된다던데 그래도 같은 오류가 뜬다, ,

로그인이 된게 맞나 싶어서 아래 라인으로 출력해줬는데 

print("AUTH_TEST:",soup.script)

로그인이 된게 맞다면

<title>
   TISTORY OAUTH
</title>

이렇게 뜬다고 한다. 근데 나는?

<title>
   TISTORY
</title>
<link href="https://t1.daumcdn.net/tistory_admin/favicon/tistory_favicon_32x32.ico" rel="icon" sizes="any"/>
<link href="https://t1.daumcdn.net/tistory_admin/top_v2/bi-tistory-favicon.svg" rel="icon" type="image/svg+xml"/>
// ...

이렇게 뜬다. OAUTH가 없이 출력돼서 로그인이 안 된 것 같다. 

그래서 개발자님 티스토리 댓글에서 같은 오류가 발생한 사람들을 찾아서 DOWNLOAD_DIR도 빈 폴더 만들고 경로 설정도 해봤지만 계속해서 똑같은 오류가 발생했다. 

 

https://github.com/jmjeon94/N2T/issues/16

 

list index out of range · Issue #16 · jmjeon94/N2T

안녕하세요. 좋은 프로그램 만들어주셔서 감사드립니다. 제가 오늘 처음 받아서 사용해 보려고 하는데, list index out of range와 같은 에러가 계속 발생하였습니다. [2023_0115_181657] [진행중] Notion 로그

github.com

 

 


아 뭐지? 왜 네트워크가 바뀌니까 오류가 안 뜨지? 잘 올라가네?

이 찝찝한 마무리

+) 왜 학교 와이파이에서만 안 되는걸까?

 

전체 참고자료

https://minimin2.tistory.com/176#google_vignette

https://github.com/jmjeon94/N2T

댓글