@@ -1836,8 +1836,12 @@ def __str__(self) -> str:
1836
1836
1837
1837
1838
1838
def get_platform () -> Platform :
1839
- system = platform .system ().lower ()
1840
- platform_name = platform .platform ().lower ()
1839
+ try :
1840
+ system = platform .system ().lower ()
1841
+ platform_name = platform .platform ().lower ()
1842
+ except Exception :
1843
+ return "Unknown"
1844
+
1841
1845
if "iphone" in platform_name or "ipad" in platform_name :
1842
1846
# Tested using Python3IDE on an iPhone 11 and Pythonista on an iPad 7
1843
1847
# system is Darwin and platform_name is a string like:
@@ -1880,8 +1884,8 @@ def platform_headers(version: str) -> Dict[str, str]:
1880
1884
"X-Stainless-Package-Version" : version ,
1881
1885
"X-Stainless-OS" : str (get_platform ()),
1882
1886
"X-Stainless-Arch" : str (get_architecture ()),
1883
- "X-Stainless-Runtime" : platform . python_implementation (),
1884
- "X-Stainless-Runtime-Version" : platform . python_version (),
1887
+ "X-Stainless-Runtime" : get_python_runtime (),
1888
+ "X-Stainless-Runtime-Version" : get_python_version (),
1885
1889
}
1886
1890
1887
1891
@@ -1897,9 +1901,27 @@ def __str__(self) -> str:
1897
1901
Arch = Union [OtherArch , Literal ["x32" , "x64" , "arm" , "arm64" , "unknown" ]]
1898
1902
1899
1903
1904
+ def get_python_runtime () -> str :
1905
+ try :
1906
+ return platform .python_implementation ()
1907
+ except Exception :
1908
+ return "unknown"
1909
+
1910
+
1911
+ def get_python_version () -> str :
1912
+ try :
1913
+ return platform .python_version ()
1914
+ except Exception :
1915
+ return "unknown"
1916
+
1917
+
1900
1918
def get_architecture () -> Arch :
1901
- python_bitness , _ = platform .architecture ()
1902
- machine = platform .machine ().lower ()
1919
+ try :
1920
+ python_bitness , _ = platform .architecture ()
1921
+ machine = platform .machine ().lower ()
1922
+ except Exception :
1923
+ return "unknown"
1924
+
1903
1925
if machine in ("arm64" , "aarch64" ):
1904
1926
return "arm64"
1905
1927
0 commit comments