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