You need to enable JavaScript to run this app.
Web Application Firewall

Web Application Firewall

Copy page
Download PDF
SDK reference
Python example
Copy page
Download PDF
Python example
This article introduces you to the download address, installation method, and code examples of the Web Application Firewall Python SDK, helping you quickly understand how to use the SDK to call the OpenAPI.​
Requirements​
  • You must have obtained the Access Key for your account. For specific steps, please refer to Obtain Access Key.​
  • You must have Python 2.7 or higher installed. Executing python --version can check the current Python version information.​
Step 1: Download SDK​
Go to volcengine-python-sdk to download the installation package for the Web Application Firewall Python SDK.​
Step 2: Install the SDK​
You can install the SDK using any of the following methods.​
Method 1​
Use the pip command to install the SDK.​
​
pip install volcengine-python-sdk​
​
Method two​
  • Execute python setup.py install --user command to install the SDK for the specified user.​
  • Execute sudo python setup.py install command to install the SDK for all users.​
Step 3: Call the interface​
Taking QueryLLMGenerate as an example to query the large model's generation results in real-time, demonstrating how to use the Python SDK to make the call.​
​
from __future__ import print_function\nimport volcenginesdkcore\nimport volcenginesdkwaf\nfrom volcenginesdkcore.rest import ApiException\n\ndef set_config():\n # Get configuration\n configuration = volcenginesdkcore.Configuration()\n configuration.ak = \"****\" # Your AK\n configuration.sk = \"****\" # Your SK\n configuration.region = \"cn-shanghai\" # Your region\n configuration.client_side_validation = True\n configuration.host = \"open.volcengineapi.com\"\n # Set configuration\n volcenginesdkcore.Configuration.set_default(configuration)\n # Get waf api handle\n global api_instance\n api_instance = volcenginesdkwaf.WAFApi()\n\n# Query the results generated by the large model\n query_llm_generate_request = volcenginesdkwaf.QueryLLMGenerateRequest(\n msg_id=msg_id,\n)\n\ntry:\n # Copy the code to run the example, please print the API return value yourself. \n response = api_instance.query_llm_generate(query_llm_generate_request)\n print(response)\nexcept ApiException as e:\n # Copy the code to run the example, please print the API error information yourself. ​
print("Exception when calling api: %s\n" % e)​
​
Explanations of the call results​
Copy and run the code example to print API error messages, as shown in the following error example.​
Success​
​
Exception when calling api: (200)\nReason: {'Code': '10001', 'Message': 'Failed to get the request information corresponding to msg_id'}​
​
Failure​
​
{'suggest': 'hello'}​
​
​
Last updated: 2025.06.30 16:25:33