2024-01-15 19:23
import lib.api as api print("This is a binary.") data = api.get_data() print(data[0]["id"])
import requests URL = "https://api.github.com/users/abronte/repos" def get_data(): resp = requests.get(URL) return resp.json()
python -m nuitka --include-package=requests --onefile --standalone main.py
Nuitka-Options:INFO: Used command line options: --include-package=requests --onefile --standalone main.py Nuitka:INFO: Starting Python compilation with Nuitka '1.9.7' on Python '3.11' commercial grade 'not installed'. Nuitka-Plugins:INFO: anti-bloat: Not including '_bisect' automatically in order to avoid bloat, but this may cause: may slow down by using fallback implementation. Nuitka-Plugins:INFO: anti-bloat: Not including '_json' automatically in order to avoid bloat, but this may cause: may slow down by using fallback implementation. Nuitka:INFO: Completed Python level compilation and optimization. Nuitka:INFO: Generating source code for C backend compiler. Nuitka:INFO: Running data composer tool for optimal constant value handling. Nuitka-DataComposer:WARNING: Problem with constant file 'module.urllib3.response.const'. Traceback (most recent call last): File "<frozen runpy>", line 198, in _run_module_as_main File "<frozen runpy>", line 88, in _run_code File "/usr/local/lib/python3.11/site-packages/nuitka/tools/data_composer/__main__.py", line 40, in <module> main() File "/usr/local/lib/python3.11/site-packages/nuitka/tools/data_composer/DataComposer.py", line 422, in main with open(fullpath, "rb") as const_file: ^^^^^^^^^^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: 'main.build/module.urllib3.response.const' FATAL: Error executing data composer, please report the above exception.
import json import http.client URL = "https://api.github.com/users/abronte/repos" def get_data(): conn = http.client.HTTPSConnection("api.github.com") # Create the request header headers = {"User-Agent": "Python HTTP Client"} # Send a GET request resource = f"/users/abronte/repos" conn.request("GET", resource, headers=headers) # Get the response response = conn.getresponse() # Check if the response status is OK if response.status == 200: # Read and decode the response data = response.read().decode() # Convert the JSON data to a Python object repos = json.loads(data) return repos else: return f"Error: {response.status}"
python -m nuitka --onefile --standalone main.py
Nuitka-Options:INFO: Used command line options: --onefile --standalone main.py Nuitka:INFO: Starting Python compilation with Nuitka '1.9.7' on Python '3.11' commercial grade 'not installed'. Nuitka-Plugins:INFO: anti-bloat: Not including '_bisect' automatically in order to avoid bloat, but this may cause: may slow down by using fallback implementation. Nuitka-Plugins:INFO: anti-bloat: Not including '_json' automatically in order to avoid bloat, but this may cause: may slow down by using fallback implementation. Nuitka:INFO: Completed Python level compilation and optimization. Nuitka:INFO: Generating source code for C backend compiler. Nuitka:INFO: Running data composer tool for optimal constant value handling. Nuitka:INFO: Running C compilation via Scons. Nuitka-Scons:INFO: Backend C compiler: gcc (gcc 12). Nuitka-Scons:INFO: Backend linking program with 9 files (no progress information available for this stage). Nuitka-Scons:WARNING: You are not using ccache, re-compilation of identical code will be slower than necessary. Use your OS package manager to install it. Nuitka-Postprocessing:INFO: Creating single file from dist folder, this may take a while. Nuitka-Onefile:INFO: Running bootstrap binary compilation via Scons. Nuitka-Scons:INFO: Onefile C compiler: gcc (gcc 12). Nuitka-Scons:INFO: Onefile linking program with 1 files (no progress information available for this stage). Nuitka-Scons:WARNING: You are not using ccache, re-compilation of identical code will be slower than necessary. Use your OS package manager to install it. Nuitka-Onefile:INFO: Using compression for onefile payload. Nuitka-Onefile:INFO: Onefile payload compression ratio (26.41%) size 43454699 to 11477256. Nuitka-Onefile:INFO: Keeping onefile build directory 'main.onefile-build'. Nuitka:INFO: Keeping dist folder 'main.dist' for inspection, no need to use it. Nuitka:INFO: Keeping build directory 'main.build'. Nuitka:INFO: Successfully created 'main.bin'.
root@93c6753650cd:/app# ./main.bin This is a binary. 88233154
root@4ff614b44b25:/app# ./main.bin This is a binary. Traceback (most recent call last): File "/tmp/onefile_9_1705345900_197091/main.py", line 5, in <module> data = api.get_data() File "/tmp/onefile_9_1705345900_197091/lib/api.py", line 29, in get_data File "/tmp/onefile_9_1705345900_197091/http/client.py", line 1286, in request File "/tmp/onefile_9_1705345900_197091/http/client.py", line 1332, in _send_request File "/tmp/onefile_9_1705345900_197091/http/client.py", line 1281, in endheaders File "/tmp/onefile_9_1705345900_197091/http/client.py", line 1041, in _send_output File "/tmp/onefile_9_1705345900_197091/http/client.py", line 979, in send File "/tmp/onefile_9_1705345900_197091/http/client.py", line 1458, in connect File "/tmp/onefile_9_1705345900_197091/ssl.py", line 517, in wrap_socket File "/tmp/onefile_9_1705345900_197091/ssl.py", line 1075, in _create File "/tmp/onefile_9_1705345900_197091/ssl.py", line 1346, in do_handshake ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)
apt-get install ca-certificates
root@4ff614b44b25:/app# ./main.bin This is a binary. 88233154