Reputation: 329
def install_build(install_info,source_url=None):
if source_url is None:
try:
version_no = install_info["version_number"]
build_no = install_info["build_number"]
if version_no is None or build_no is None:
raise ValueError("Please specifiy the value(s) for either the source_url or version number and the build number")
except KeyError:
print("You are missing either or both of these keys: version number or build number")
# If the necessary parameters are present, call the method to install the build
install_build_on_server(version_no,build_no,source_url)
if __name__ == "__main__":
install_build(
{
"product_type":"abc",
"username":"def",
"version_number":None,
"build_number":"123",
"password":"xyz"
}
)
The above method tries to install a build either from a source url [of the installer] or by collectively taking the build and version number and queries the build repository, gets the repository and installs the build. Thus, either the source url can be None or the version_number and build_number can be None not both. I have written the error handling for the same. But my application fails to handle the error for the above scenario. Could any one let me know what i am missing?
Here is the output of the program:
Traceback (most recent call last):
File "test.py", line 18, in <module>
"password":"xyz"
File "test.py", line 7, in install_build
raise ValueError("Please specifiy the value(s) for either the source_url or version number and the build number")
ValueError: Please specifiy the value(s) for either the source_url or version number and the build number
Upvotes: 0
Views: 607
Reputation: 1
Check both with and : if version_no is None and build_no is None:
Since version_no you are passing is None which raises a Value error in (OR) part.Either change the condition or pass a value other than None in both version_no and build_no.
Upvotes: 0
Reputation: 987
if version_no is None or build_no is None:
should be
if version_no is None and build_no is None:
Upvotes: 1