fix(praw): fixed auth error for new praw version
This commit is contained in:
@@ -9,7 +9,9 @@ import socket
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import praw
|
import praw
|
||||||
|
import prawcore
|
||||||
import requests
|
import requests
|
||||||
|
from praw.util.token_manager import BaseTokenManager
|
||||||
|
|
||||||
from bdfr.exceptions import BulkDownloaderException, RedditAuthenticationError
|
from bdfr.exceptions import BulkDownloaderException, RedditAuthenticationError
|
||||||
|
|
||||||
@@ -87,13 +89,13 @@ class OAuth2Authenticator:
|
|||||||
client.close()
|
client.close()
|
||||||
|
|
||||||
|
|
||||||
class OAuth2TokenManager(praw.reddit.BaseTokenManager):
|
class OAuth2TokenManager(BaseTokenManager):
|
||||||
def __init__(self, config: configparser.ConfigParser, config_location: Path):
|
def __init__(self, config: configparser.ConfigParser, config_location: Path):
|
||||||
super(OAuth2TokenManager, self).__init__()
|
super(OAuth2TokenManager, self).__init__()
|
||||||
self.config = config
|
self.config = config
|
||||||
self.config_location = config_location
|
self.config_location = config_location
|
||||||
|
|
||||||
def pre_refresh_callback(self, authorizer: praw.reddit.Authorizer):
|
def pre_refresh_callback(self, authorizer: prawcore.auth.BaseAuthorizer):
|
||||||
if authorizer.refresh_token is None:
|
if authorizer.refresh_token is None:
|
||||||
if self.config.has_option("DEFAULT", "user_token"):
|
if self.config.has_option("DEFAULT", "user_token"):
|
||||||
authorizer.refresh_token = self.config.get("DEFAULT", "user_token")
|
authorizer.refresh_token = self.config.get("DEFAULT", "user_token")
|
||||||
@@ -101,7 +103,7 @@ class OAuth2TokenManager(praw.reddit.BaseTokenManager):
|
|||||||
else:
|
else:
|
||||||
raise RedditAuthenticationError("No auth token loaded in configuration")
|
raise RedditAuthenticationError("No auth token loaded in configuration")
|
||||||
|
|
||||||
def post_refresh_callback(self, authorizer: praw.reddit.Authorizer):
|
def post_refresh_callback(self, authorizer: prawcore.auth.BaseAuthorizer):
|
||||||
self.config.set("DEFAULT", "user_token", authorizer.refresh_token)
|
self.config.set("DEFAULT", "user_token", authorizer.refresh_token)
|
||||||
with Path(self.config_location).open(mode="w") as file:
|
with Path(self.config_location).open(mode="w") as file:
|
||||||
self.config.write(file, True)
|
self.config.write(file, True)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ dependencies = [
|
|||||||
"beautifulsoup4>=4.10.0",
|
"beautifulsoup4>=4.10.0",
|
||||||
"click>=8.0.0",
|
"click>=8.0.0",
|
||||||
"dict2xml>=1.7.0",
|
"dict2xml>=1.7.0",
|
||||||
"praw>=7.2.0",
|
"praw>=7.8.1",
|
||||||
"pyyaml>=5.4.1",
|
"pyyaml>=5.4.1",
|
||||||
"requests>=2.25.1",
|
"requests>=2.25.1",
|
||||||
"yt-dlp>=2022.11.11",
|
"yt-dlp>=2022.11.11",
|
||||||
|
|||||||
Reference in New Issue
Block a user