diff --git a/tests/tests.py b/tests/tests.py index fb286922d..c1f1ba4c6 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -2634,6 +2634,28 @@ def test_wsgi_query_string_with_encodechars(self): expected = "query=Jane%26John&otherquery=B&test=hello%2Bm.te%26how%26are%26you" self.assertEqual(request["QUERY_STRING"], expected) + @mock.patch("subprocess.Popen") + def test_create_handler_venv_win32_none_stderror_result(self, popen_mock): + class PopenMock: + returncode = 999 + + @classmethod + def communicate(cls): + return "valid_stdout", None # On win32, stderr can be None + + popen_mock.return_value = PopenMock + + boto_mock = mock.MagicMock() + zappa_core = Zappa( + boto_session=boto_mock, + profile_name="test", + aws_region="test", + load_credentials=True, + ) + + with self.assertRaises(EnvironmentError): + zappa_core.create_handler_venv() + if __name__ == "__main__": unittest.main() diff --git a/zappa/core.py b/zappa/core.py index 12a143be0..e603ce6a4 100644 --- a/zappa/core.py +++ b/zappa/core.py @@ -310,7 +310,7 @@ def __init__( self.manylinux_wheel_file_match = re.compile( rf'^.*{self.manylinux_suffix_start}-(manylinux_\d+_\d+_x86_64[.])?manylinux({"|".join(self.manylinux_suffixes)})_x86_64[.]whl$' # noqa: E501 ) - self.manylinux_wheel_abi3_file_match = re.compile(rf"^.*cp3.-abi3-manylinux.*_x86_64[.]whl$") + self.manylinux_wheel_abi3_file_match = re.compile(r"^.*cp3.-abi3-manylinux.*_x86_64[.]whl$") self.endpoint_urls = endpoint_urls self.xray_tracing = xray_tracing @@ -488,9 +488,9 @@ def create_handler_venv(self, use_zappa_release: Optional[str] = None): if pip_return_code: logger.info("command: %s", " ".join(command)) - if stdout_result.strip(): + if stdout_result and stdout_result.strip(): logger.info("stdout: %s", stdout_result.strip()) - if stderror_result.strip(): + if stderror_result and stderror_result.strip(): logger.error("stderr: %s", stderror_result) raise EnvironmentError("Pypi lookup failed") diff --git a/zappa/middleware.py b/zappa/middleware.py index 920db0c94..2cebcebfb 100644 --- a/zappa/middleware.py +++ b/zappa/middleware.py @@ -44,11 +44,11 @@ def encode_response(status, headers, exc_info=None): Related: https://github.com/Miserlou/Zappa/issues/1965 """ - new_headers = [header for header in headers if ((type(header[0]) != str) or (header[0].lower() != "set-cookie"))] + new_headers = [header for header in headers if isinstance(header[0], str) or header[0].lower() != "set-cookie"] cookie_headers = [ (header[0].lower(), header[1]) for header in headers - if ((type(header[0]) == str) and (header[0].lower() == "set-cookie")) + if isinstance(header[0], str) and header[0].lower() == "set-cookie" ] new_headers = new_headers + cookie_headers