Skip to content

Commit b1cb295

Browse files
committed
fixd #60
1 parent 99facc2 commit b1cb295

File tree

4 files changed

+35
-15
lines changed

4 files changed

+35
-15
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434

3535
# 更新日志
3636

37+
## `v2.6.5`
38+
39+
- 修复蓝奏云主域名解析异常的问题[#59](https://github.com/zaxtyson/LanZouCloud-API/issues/59) [#60](https://github.com/zaxtyson/LanZouCloud-API/pull/60)
40+
3741
## `v2.6.4`
3842

3943
- 修复无法获取分享文件夹信息的问题[#58](https://github.com/zaxtyson/LanZouCloud-API/pull/58)

lanzou/api/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from lanzou.api.core import LanZouCloud
22

3-
version = '2.6.4'
3+
version = '2.6.5'
44

55
__all__ = ['utils', 'types', 'models', 'LanZouCloud', 'version']

lanzou/api/core.py

+29-13
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(self):
4545
self._timeout = 15 # 每个请求的超时(不包含下载响应体的用时)
4646
self._max_size = 100 # 单个文件大小上限 MB
4747
self._upload_delay = (0, 0) # 文件上传延时
48-
self._host_url = 'https://pan.lanzous.com'
48+
self._host_url = 'https://pan.lanzoui.com'
4949
self._doupload_url = 'https://pc.woozooo.com/doupload.php'
5050
self._account_url = 'https://pc.woozooo.com/account.php'
5151
self._mydisk_url = 'https://pc.woozooo.com/mydisk.php'
@@ -58,20 +58,36 @@ def __init__(self):
5858
disable_warnings(InsecureRequestWarning) # 全局禁用 SSL 警告
5959

6060
def _get(self, url, **kwargs):
61-
try:
62-
kwargs.setdefault('timeout', self._timeout)
63-
kwargs.setdefault('headers', self._headers)
64-
return self._session.get(url, verify=False, **kwargs)
65-
except (ConnectionError, requests.RequestException):
66-
return None
61+
for possible_url in self._all_possible_urls(url):
62+
try:
63+
kwargs.setdefault('timeout', self._timeout)
64+
kwargs.setdefault('headers', self._headers)
65+
return self._session.get(possible_url, verify=False, **kwargs)
66+
except (ConnectionError, requests.RequestException):
67+
logger.debug(f"Get {possible_url} failed, try another domain")
68+
69+
return None
6770

6871
def _post(self, url, data, **kwargs):
69-
try:
70-
kwargs.setdefault('timeout', self._timeout)
71-
kwargs.setdefault('headers', self._headers)
72-
return self._session.post(url, data, verify=False, **kwargs)
73-
except (ConnectionError, requests.RequestException):
74-
return None
72+
for possible_url in self._all_possible_urls(url):
73+
try:
74+
kwargs.setdefault('timeout', self._timeout)
75+
kwargs.setdefault('headers', self._headers)
76+
return self._session.post(possible_url, data, verify=False, **kwargs)
77+
except (ConnectionError, requests.RequestException):
78+
logger.debug(f"Post to {possible_url} ({data}) failed, try another domain")
79+
80+
return None
81+
82+
@staticmethod
83+
def _all_possible_urls(url: str) -> List[str]:
84+
"""蓝奏云的主域名有时会挂掉, 此时尝试切换到备用域名"""
85+
available_domains = [
86+
'lanzoui.com', # 鲁ICP备15001327号-6, 2020-06-09, SEO 排名最低
87+
'lanzoux.com', # 鲁ICP备15001327号-5, 2020-06-09
88+
'lanzous.com' # 主域名, 备案异常, 部分地区已经无法访问
89+
]
90+
return [url.replace('lanzous.com', d) for d in available_domains]
7591

7692
def ignore_limits(self):
7793
"""解除官方限制"""

lanzou/api/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
headers = {
2828
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
29-
'Referer': 'https://pan.lanzous.com',
29+
# 'Referer': 'https://pan.lanzous.com', # 可以没有
3030
'Accept-Language': 'zh-CN,zh;q=0.9',
3131
}
3232

0 commit comments

Comments
 (0)