mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-04-13 11:39:50 +08:00
fix httpx
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
import httpx
|
||||
import requests
|
||||
|
||||
from app.core.cache import cached
|
||||
from app.core.config import settings
|
||||
from app.utils.asyncio import AsyncUtils
|
||||
from app.utils.http import RequestUtils, AsyncRequestUtils
|
||||
|
||||
|
||||
@@ -30,9 +28,8 @@ class BangumiApi(object):
|
||||
|
||||
def __init__(self):
|
||||
self._session = requests.Session()
|
||||
self._req = RequestUtils(session=self._session)
|
||||
self._client = httpx.AsyncClient()
|
||||
self._async_req = AsyncRequestUtils(client=self._client)
|
||||
self._req = RequestUtils(ua=settings.NORMAL_USER_AGENT, session=self._session)
|
||||
self._async_req = AsyncRequestUtils(ua=settings.NORMAL_USER_AGENT)
|
||||
|
||||
@cached(maxsize=settings.CONF.bangumi, ttl=settings.CONF.meta)
|
||||
def __invoke(self, url, key: Optional[str] = None, **kwargs):
|
||||
@@ -306,5 +303,3 @@ class BangumiApi(object):
|
||||
def close(self):
|
||||
if self._session:
|
||||
self._session.close()
|
||||
if self._client:
|
||||
AsyncUtils.run_async(self._client.aclose())
|
||||
|
||||
@@ -12,7 +12,6 @@ import requests
|
||||
|
||||
from app.core.cache import cached
|
||||
from app.core.config import settings
|
||||
from app.utils.asyncio import AsyncUtils
|
||||
from app.utils.http import RequestUtils, AsyncRequestUtils
|
||||
from app.utils.singleton import WeakSingleton
|
||||
|
||||
@@ -156,7 +155,6 @@ class DoubanApi(metaclass=WeakSingleton):
|
||||
|
||||
def __init__(self):
|
||||
self._session = requests.Session()
|
||||
self._client = httpx.AsyncClient()
|
||||
|
||||
@classmethod
|
||||
def __sign(cls, url: str, ts: str, method='GET') -> str:
|
||||
@@ -251,8 +249,7 @@ class DoubanApi(metaclass=WeakSingleton):
|
||||
"""
|
||||
req_url, params = self._prepare_get_request(url, **kwargs)
|
||||
resp = await AsyncRequestUtils(
|
||||
ua=choice(self._user_agents),
|
||||
client=self._client
|
||||
ua=choice(self._user_agents)
|
||||
).get_res(url=req_url, params=params)
|
||||
return self._handle_response(resp)
|
||||
|
||||
@@ -297,8 +294,7 @@ class DoubanApi(metaclass=WeakSingleton):
|
||||
"""
|
||||
req_url, params = self._prepare_post_request(url, **kwargs)
|
||||
resp = await AsyncRequestUtils(
|
||||
ua=settings.NORMAL_USER_AGENT,
|
||||
client=self._client
|
||||
ua=settings.NORMAL_USER_AGENT
|
||||
).post_res(url=req_url, data=params)
|
||||
return self._handle_response(resp)
|
||||
|
||||
@@ -876,5 +872,3 @@ class DoubanApi(metaclass=WeakSingleton):
|
||||
def close(self):
|
||||
if self._session:
|
||||
self._session.close()
|
||||
if self._client:
|
||||
AsyncUtils.run_async(self._client.aclose())
|
||||
|
||||
@@ -5,13 +5,11 @@ import logging
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
import httpx
|
||||
import requests
|
||||
import requests.exceptions
|
||||
|
||||
from app.core.cache import cached
|
||||
from app.core.config import settings
|
||||
from app.utils.asyncio import AsyncUtils
|
||||
from app.utils.http import RequestUtils, AsyncRequestUtils
|
||||
from .exceptions import TMDbException
|
||||
|
||||
@@ -20,12 +18,11 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
class TMDb(object):
|
||||
|
||||
def __init__(self, obj_cached=True, session=None, client=None, language=None):
|
||||
def __init__(self, obj_cached=True, session=None, language=None):
|
||||
self._api_key = settings.TMDB_API_KEY
|
||||
self._language = language or settings.TMDB_LOCALE or "en-US"
|
||||
self._session_id = None
|
||||
self._session = session
|
||||
self._client = client
|
||||
self._wait_on_rate_limit = True
|
||||
self._debug_enabled = False
|
||||
self._cache_enabled = obj_cached
|
||||
@@ -37,11 +34,9 @@ class TMDb(object):
|
||||
|
||||
if not self._session:
|
||||
self._session = requests.Session()
|
||||
self._req = RequestUtils(session=self._session, proxies=self.proxies)
|
||||
self._req = RequestUtils(ua=settings.NORMAL_USER_AGENT, session=self._session, proxies=self.proxies)
|
||||
|
||||
if not self._client:
|
||||
self._client = httpx.AsyncClient()
|
||||
self._async_req = AsyncRequestUtils(client=self._client, proxies=self.proxies)
|
||||
self._async_req = AsyncRequestUtils(ua=settings.NORMAL_USER_AGENT, proxies=self.proxies)
|
||||
|
||||
self._remaining = 40
|
||||
self._reset = None
|
||||
@@ -279,5 +274,3 @@ class TMDb(object):
|
||||
def close(self):
|
||||
if self._session:
|
||||
self._session.close()
|
||||
if self._client:
|
||||
AsyncUtils.run_async(self._client.aclose())
|
||||
|
||||
Reference in New Issue
Block a user