Skip to content

Commit

Permalink
Fixed the param passed to request s proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan-1F committed Nov 30, 2022
1 parent d16ed39 commit bae87fe
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions mcdreforged_plugin_manager/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ class Configure(Serializable):
install_path: str = 'plugins'
proxy: ProxyConfig = ProxyConfig.get_default()

@property
def request_proxy(self) -> dict:
param = {}
for k, v in self.proxy.serialize().items():
if v is not None:
param[k] = v
return param if param else None

@property
def get_source(self) -> str:
return self.source.rstrip('/')
Expand Down
2 changes: 1 addition & 1 deletion mcdreforged_plugin_manager/storage/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def cache(self):
before = self.plugin_amount
try:
psi.logger.info(tr('cache.cache'))
data = requests.get(config.get_source + '/plugins.json', timeout=config.timeout, proxies=config.proxy).json()
data = requests.get(config.get_source + '/plugins.json', timeout=config.timeout, proxies=config.request_proxy).json()
self.update_from(data)
self.save()
except requests.RequestException as e:
Expand Down
2 changes: 1 addition & 1 deletion mcdreforged_plugin_manager/storage/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ def get_latest_release(self) -> Optional[ReleaseInfo]:
@classmethod
def of(cls, plugin_id: str) -> 'ReleaseSummary':
data = requests.get('{}/{}/release.json'.format(config.get_source, plugin_id),
timeout=config.timeout, proxies=config.proxy).json()
timeout=config.timeout, proxies=config.request_proxy).json()
return cls.deserialize(data)
2 changes: 1 addition & 1 deletion mcdreforged_plugin_manager/util/network_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def download_file(url: str, path: str):
data = requests.get(url, timeout=config.timeout, proxies=config.proxy)
data = requests.get(url, timeout=config.timeout, proxies=config.request_proxy)
with open(path, 'wb') as f:
for chunk in data.iter_content():
if chunk is not None:
Expand Down

0 comments on commit bae87fe

Please sign in to comment.