fix(proxy): raise ValueError for unknown IP_PROXY_PROVIDER_NAME instead of crashing with AttributeError#925
Open
kapil971390 wants to merge 1 commit into
Conversation
When IP_PROXY_PROVIDER_NAME in config.py is set to an unrecognised value (e.g. typo "kuaidalli" instead of "kuaidaili"), IpProxyProvider.get() returns None which is silently stored in ProxyIpPool.ip_provider. The crash surfaces later as: AttributeError: 'NoneType' object has no attribute 'get_proxy' with no hint about what went wrong or how to fix it. Add an explicit None-check in create_ip_pool() that raises ValueError with the bad name and the list of valid options, so the root cause is immediately visible. Also add a regression test covering the four invalid-name edge cases (typo, empty string, wrong case, unknown name) and the three valid names to confirm they are unaffected.
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


问题
当
config.py中IP_PROXY_PROVIDER_NAME被设置为一个不存在于IpProxyProvider字典中的值时(例如把"kuaidaili"拼写成"kuaidalli"),IpProxyProvider.get()会返回None,这个None被静默地传入ProxyIpPool.ip_provider。程序在启动时没有任何报错,直到调用
load_proxies()时才崩溃:此错误信息完全不提示根本原因,用户很难判断问题出在
IP_PROXY_PROVIDER_NAME配置上。复现步骤
config/base_config.py中将IP_PROXY_PROVIDER_NAME改为错误值,例如"kuaidalli"ENABLE_IP_PROXY = Truecreate_ip_pool()→load_proxies()抛出AttributeError: 'NoneType' object has no attribute 'get_proxy'方案
在
create_ip_pool()中,.get()取到None时立即抛出ValueError,并在错误信息中列出有效选项:修复后:
测试
在
test/test_proxy_ip_pool.py新增回归测试,覆盖拼写错误、空字符串、大小写错误及三个合法 provider 名称不受影响。🤖 Generated with Claude Code