### Setup Virtual Environment and Install Dependencies Source: https://github.com/netgsm/netgsm-sms-python/blob/main/CONTRIBUTING.md Creates a Python virtual environment named 'venv', activates it, and installs the project's development dependencies using pip. ```bash python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -e ".[dev]" ``` -------------------------------- ### Install Dependencies with Pip (Bash) Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/DEVELOPMENT.md Installs all required Python packages listed in the `requirements.txt` file. This command should be run after activating the virtual environment. ```bash pip install -r requirements.txt ``` -------------------------------- ### Create .env Configuration File (Bash) Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/DEVELOPMENT.md Copies the example environment file to create a new `.env` file. This file will store sensitive credentials and configuration settings. ```bash cp .env.example .env ``` -------------------------------- ### Install Netgsm Python SDK Source: https://github.com/netgsm/netgsm-sms-python/blob/main/README.md Installs the Netgsm Python SDK using pip. This is the first step to start using the SDK in your Python projects. ```bash pip install netgsm-sms ``` -------------------------------- ### Copy Environment Configuration Source: https://github.com/netgsm/netgsm-sms-python/blob/main/CONTRIBUTING.md Copies the example environment file (.env.example) to a new file (.env) to allow users to configure their credentials. ```bash cp .env.example .env ``` -------------------------------- ### Copy Example Environment File Source: https://github.com/netgsm/netgsm-sms-python/blob/main/README.md Copies the example environment file to a new file, which can then be edited with user-specific credentials. ```bash cp .env.example .env ``` -------------------------------- ### Clone Netgsm Python SDK Repository (Bash) Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/DEVELOPMENT.md Clones the Netgsm Python SDK repository from GitHub to your local machine. This is the first step to start development or testing. ```bash git clone https://github.com/netgsm/netgsm-sms-python.git cd netgsm-sms-python ``` -------------------------------- ### Install Netgsm Python SDK Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/README.md Installs the Netgsm Python SDK using pip. This is the first step to integrate Netgsm SMS services into your Python applications. ```bash pip install netgsm-sms ``` -------------------------------- ### Create .env file for Netgsm SDK Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/INTEGRATION_TESTING.md Copies the example environment file to be configured with Netgsm API credentials and test parameters. This file is essential for running the integration tests. ```bash cp .env.example .env ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/netgsm/netgsm-sms-python/blob/main/README.md Shows how to set up environment variables for Netgsm SDK credentials. This is useful for managing sensitive information and running examples. ```dotenv NETGSM_USERNAME=YOUR_USERNAME NETGSM_PASSWORD=YOUR_PASSWORD NETGSM_MSGHEADER=YOUR_SMS_HEADER NETGSM_APPNAME=YOUR_APP_NAME ``` -------------------------------- ### Set Up Virtual Environment (Bash) Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/DEVELOPMENT.md Creates and activates a Python virtual environment to isolate project dependencies. This ensures that the SDK's dependencies do not conflict with other Python projects. ```bash # Using virtualenv python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate # Or using pipenv pipenv shell ``` -------------------------------- ### Package SDK for Distribution (Bash) Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/DEVELOPMENT.md Creates source distribution (`sdist`) and built distribution (`bdist_wheel`) archives for the Netgsm Python SDK. These packages are used for distributing the SDK. ```bash python setup.py sdist bdist_wheel ``` -------------------------------- ### Upload SDK to PyPI with Twine (Bash) Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/DEVELOPMENT.md Uploads the packaged SDK distribution files to the Python Package Index (PyPI). This command is typically used by project maintainers to release new versions. ```bash twine upload dist/* ``` -------------------------------- ### Run All SDK Tests (Bash) Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/DEVELOPMENT.md Executes all unit tests for the Netgsm Python SDK using the `unittest` module. This is crucial for verifying the SDK's functionality and ensuring no regressions. ```bash python -m unittest discover ``` -------------------------------- ### Run Specific Test File (Bash) Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/DEVELOPMENT.md Runs unit tests from a particular file within the `tests` directory. This is useful for debugging or focusing on specific components of the SDK. ```bash python -m unittest tests/test_sms_service.py ``` -------------------------------- ### Handle Netgsm API Errors in Python Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/README.md Provides an example of how to catch and handle specific Netgsm API exceptions in your Python code. This allows for graceful error reporting and recovery. ```python try: response = netgsm.sms.send( msgheader="BASLIK", messages=[ { "msg": "Test message", "no": "5XXXXXXXXX" } ] ) print(f"SMS sent. JobID: {response.get('jobid')}") except NotAcceptableException as e: print(f"Netgsm error: {e.message}") print(f"HTTP status: {e.http_status}") print(f"Error code: {e.code}") # Perform action based on error code if e.code == "40": print("Message header not defined!") elif e.code == "30": print("Invalid or missing credentials or API access!") elif e.code == "20": print("Message text too long or invalid!") except TimeoutException as e: print(f"Timeout error: {e.message}") except ConnectionException as e: print(f"Connection error: {e.message}") except ApiException as e: print(f"General API error: {e.message}") ``` -------------------------------- ### Handle Netgsm API Errors Source: https://github.com/netgsm/netgsm-sms-python/blob/main/README.md Provides an example of how to use try-except blocks to catch specific Netgsm API exceptions, such as NotAcceptableException, and extract error details. ```python from netgsm import Netgsm from netgsm.exceptions.api_exception import ApiException, NotAcceptableException # Initialize Netgsm client netgsm = Netgsm(username="user", password="pass") try: # Send SMS response = netgsm.sms.send( msgheader="HEADER", messages=[ { "msg": "Test message", "no": "5XXXXXXXXX" } ] ) print(f"SMS sent. JobID: {response.get('jobid')}") except NotAcceptableException as e: # Error returned by Netgsm print(f"Netgsm error: {e.message}") print(f"HTTP status: {e.http_status}") print(f"Error code: {e.code}") except ApiException as e: # General API error print(f"API error: {e.message}") ``` -------------------------------- ### Configure Netgsm Credentials in .env (Text) Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/DEVELOPMENT.md Edits the `.env` file to add your specific Netgsm API username, password, and SMS header. These credentials are required for the SDK to authenticate and send messages. ```text NETGSM_USERNAME=YOUR_USERNAME NETGSM_PASSWORD=YOUR_PASSWORD NETGSM_MSGHEADER=YOUR_SMS_HEADER ``` -------------------------------- ### Get SMS Report with Netgsm Python SDK Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/README.md Retrieves reports for sent SMS messages. Reports can be fetched by `jobids` or by a date range. ```python response = netgsm.sms.get_report( jobids=["12345678"] # Or startdate="01.01.2023 00:00:00", stopdate="31.01.2023 23:59:59", ) ``` -------------------------------- ### Check Code with Flake8 (Bash) Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/DEVELOPMENT.md Applies PEP 8 coding standards to the project's code using the `flake8` tool. This helps maintain code quality and consistency across the SDK. ```bash flake8 netgsm ``` -------------------------------- ### Initialize and Send SMS Source: https://github.com/netgsm/netgsm-sms-python/blob/main/README.md Demonstrates how to initialize the Netgsm SDK with credentials and send an SMS message. It includes placeholders for username, password, and app name. ```python from netgsm import Netgsm # Initialize the SDK netgsm = Netgsm( username="YOUR_USERNAME", # Your Netgsm username password="YOUR_PASSWORD", # Your Netgsm password appname="YOUR_APP_NAME" # Optional, your application name ) # Send SMS response = netgsm.sms.send( msgheader="HEADER", messages=[ { "msg": "Hello, this is a test message.", "no": "5XXXXXXXXX" } ] ) print(response) ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/netgsm/netgsm-sms-python/blob/main/CONTRIBUTING.md Clones the Netgsm Python SDK repository from GitHub and navigates into the project directory. ```bash git clone https://github.com/netgsm/netgsm-sms-python.git cd netgsm-python ``` -------------------------------- ### Authenticate Netgsm Python SDK Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/README.md Demonstrates how to initialize the Netgsm client with your account credentials. This client object is used to interact with the Netgsm SMS API. ```python from netgsm import Netgsm netgsm = Netgsm( username="YOUR_USERNAME", password="YOUR_PASSWORD", appname="YOUR_APP_NAME" # Optional ) ``` -------------------------------- ### Run Tests with Coverage Source: https://github.com/netgsm/netgsm-sms-python/blob/main/CONTRIBUTING.md Runs tests using pytest and generates a code coverage report for the 'netgsm' module. ```bash pytest --cov=netgsm tests/ ``` -------------------------------- ### Run Tests Source: https://github.com/netgsm/netgsm-sms-python/blob/main/CONTRIBUTING.md Executes all tests defined in the project using the pytest framework. ```bash pytest ``` -------------------------------- ### Send SMS with Netgsm Python SDK Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/README.md Shows how to send a single or bulk SMS message using the SDK. Requires a message header and a list of messages with content and recipient numbers. ```python # Sending single SMS response = netgsm.sms.send( msgheader="HEADER", messages=[ { "msg": "Hello world!", "no": "5XXXXXXXXX" } ] ) # Sending bulk SMS response = netgsm.sms.send( msgheader="HEADER", messages=[ { "msg": "Hello world!", "no": "5XXXXXXXXX" }, { "msg": "Hello Türkiye!", "no": "5XXXXXXXXX" } ] ) ``` -------------------------------- ### Check Code Quality Source: https://github.com/netgsm/netgsm-sms-python/blob/main/CONTRIBUTING.md Runs flake8 and black --check to verify code style and formatting against the project's standards. ```bash flake8 netgsm black --check netgsm ``` -------------------------------- ### Run Netgsm Python SDK Integration Tests Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/INTEGRATION_TESTING.md Executes the integration tests for the Netgsm Python SDK. Note that these tests interact with the live Netgsm API and may consume credits. User confirmation is required before execution. ```bash python run_integration_tests.py ``` -------------------------------- ### Send Scheduled SMS with Netgsm Python SDK Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/README.md Enables sending SMS messages at a specified future date and time. The `startdate` parameter defines when the message should be delivered. ```python response = netgsm.sms.send( msgheader="HEADER", messages=[ { "msg": "Hello world!", "no": "5XXXXXXXXX" } ], startdate="ddMMyyyyHHmm" # Example: 010120231200 (January 1, 2023, 12:00) ) ``` -------------------------------- ### List SMS Headers with Netgsm Python SDK Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/README.md Fetches a list of available SMS headers (sender names) associated with your Netgsm account. ```python response = netgsm.sms.get_headers() ``` -------------------------------- ### Format Code Source: https://github.com/netgsm/netgsm-sms-python/blob/main/CONTRIBUTING.md Uses the 'black' formatter to automatically reformat the Python code in the 'netgsm' directory according to project standards. ```bash black netgsm ``` -------------------------------- ### Netgsm SDK Exception Classes Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/README.md Lists the custom exception classes provided by the Netgsm SDK for handling API-specific errors. These exceptions help in robust error management. ```python from netgsm.exceptions import ( ApiException, # Base API exception class HttpException, # Base class for HTTP errors BadRequestException, # HTTP 400 UnauthorizedException, # HTTP 401 ForbiddenException, # HTTP 403 NotFoundException, # HTTP 404 NotAcceptableException, # HTTP 406 ServerException, # HTTP 5xx TimeoutException, # Request timeout ConnectionException # Connection error ) ``` -------------------------------- ### Netgsm API Error Handling and Codes Source: https://github.com/netgsm/netgsm-sms-python/blob/main/README.md Details on how the Netgsm Python SDK handles API errors, including specific exception types, HTTP status codes, and Netgsm-specific error codes for troubleshooting. ```APIDOC Netgsm SDK Error Handling: The SDK provides a robust error handling mechanism using custom exception classes derived from a base ApiException. Exception Hierarchy: - ApiException: Base class for all SDK-related errors. - HttpException: Base class for HTTP-specific errors. - BadRequestException (400) - UnauthorizedException (401) - ForbiddenException (403) - NotFoundException (404) - NotAcceptableException (406): Commonly used by Netgsm API for business logic errors. - ServerException (5xx): For server-side issues. - TimeoutException: For request timeouts. - ConnectionException: For network connectivity issues. HTTP Status Codes: - HTTP 200 (OK): Operation successful. - HTTP 406 (Not Acceptable): Indicates an error returned by the Netgsm API, often due to invalid parameters, credentials, or business logic violations. Netgsm API Error Codes (often returned with HTTP 406): - Code 20: Message text issue or exceeded character limit. - Code 30: Invalid username, password, or IP restriction. - Code 40: Message header (sender name) not defined. - Code 50: IYS controlled submissions not allowed for the subscriber account. - Code 51: No IYS Brand information found for the subscription. - Code 60: Specified JobID not found. - Code 70: Invalid query parameters or missing required fields. - Code 80: Sending limit exceeded. - Code 85: Duplicate sending limit exceeded (e.g., >20 tasks for the same number within 1 minute). The SDK maps these Netgsm error codes to the `NotAcceptableException` and includes the code and description in the exception object. ``` -------------------------------- ### Import Netgsm Exception Classes Source: https://github.com/netgsm/netgsm-sms-python/blob/main/README.md Imports various custom exception classes provided by the Netgsm SDK for handling API-related errors. ```python from netgsm.exceptions.api_exception import ( ApiException, # Base API exception class HttpException, # Base class for HTTP errors BadRequestException, # HTTP 400 errors UnauthorizedException, # HTTP 401 errors ForbiddenException, # HTTP 403 errors NotFoundException, # HTTP 404 errors NotAcceptableException, # HTTP 406 errors (Netgsm errors usually return this way) TimeoutException, # Timeout errors ConnectionException, # Connection errors ServerException # HTTP 5XX server errors ) ``` -------------------------------- ### Netgsm API HTTP Status Codes and Error Handling Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/INTEGRATION_TESTING.md Details the HTTP status codes returned by the Netgsm API and the corresponding custom exception classes within the Python SDK. It also lists common Netgsm API error codes associated with HTTP 406 responses. ```APIDOC Netgsm API Error Handling: HTTP Status Codes: - 200 (OK): Operation successful. - 400 (Bad Request): Request format is incorrect. - 401 (Unauthorized): Authorization failed, credentials are incorrect. - 403 (Forbidden): Permission denied for the operation. - 404 (Not Found): The requested resource was not found. - 406 (Not Acceptable): Operation not acceptable; Netgsm API returned an operation-specific error. - 408 (Request Timeout): Request timed out. - 5XX (Server Error): An error occurred on the server side. Custom Exception Classes (Python SDK): - ApiException: Base class for all API exceptions. - HttpException: Base class for HTTP errors. - BadRequestException: For HTTP 400 errors. - UnauthorizedException: For HTTP 401 errors. - ForbiddenException: For HTTP 403 errors. - NotFoundException: For HTTP 404 errors. - NotAcceptableException: For HTTP 406 errors (operation-specific errors). - TimeoutException: Represents request timeouts. - ConnectionException: Represents connection errors. - ServerException: Represents HTTP 5XX server errors. Each exception object contains: message, code, http_status, and response. Netgsm API Error Codes (with HTTP 406): - 20: Message text issue or exceeded character limit. - 30: Invalid username/password or IP restriction. - 40: Message header not defined. - 50: IYS controlled submissions not allowed for subscriber account. - 51: No IYS Brand information found. - 60: Specified JobID not found. - 70: Invalid query parameters or missing required fields. - 80: Sending limit exceeded. - 85: Duplicate sending limit exceeded (max 20 tasks/minute for same number). If an error code is not listed, it is marked as 'Undefined error code'. ``` -------------------------------- ### Python Error Handling for Netgsm SMS API Source: https://github.com/netgsm/netgsm-sms-python/blob/main/README.md Demonstrates how to catch and handle specific exceptions like NotAcceptableException when sending SMS messages via the Netgsm API. It shows conditional logic based on error codes returned by the API, providing user-friendly messages for common issues such as undefined message headers or invalid credentials. ```python try: response = netgsm.sms.send(...) except NotAcceptableException as e: if e.code == "40": print("Message header is not defined!") elif e.code == "30": print("Invalid credentials or no API access!") else: print(f"Netgsm error: {e.message}") ``` -------------------------------- ### Commit Message Format Source: https://github.com/netgsm/netgsm-sms-python/blob/main/CONTRIBUTING.md Specifies the conventional commit message format for contributions, including types like feat, fix, docs, test, and refactor. ```git feat: add new feature X fix: resolve issue with Y docs: update documentation for Z test: add tests for feature W refactor: improve implementation of V ``` -------------------------------- ### Netgsm API Common Error Codes and Handling Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/INTEGRATION_TESTING.md This section details common error codes returned by the Netgsm API, their corresponding meanings, and how these errors are typically handled in Python integrations. Errors with HTTP status code 406 result in a `NotAcceptableException` with the error code in the `code` field. ```APIDOC Netgsm API Error Codes: - **30**: Invalid username, password, or API access is inactive. - HTTP Status: 406 - Python Exception: NotAcceptableException - Error Field: "30" - **40**: Message header (originator) is not defined in the system. - HTTP Status: 406 - Python Exception: NotAcceptableException - Error Field: "40" - **60**: Specified JobID not found. - HTTP Status: 406 - Python Exception: NotAcceptableException - Error Field: "60" - **70**: Invalid query, missing or incorrect parameters. - HTTP Status: 406 - Python Exception: NotAcceptableException - Error Field: "70" - **85**: Customer IP address restricted. - HTTP Status: 406 - Python Exception: NotAcceptableException - Error Field: "85" General Error Handling: - Integration tests use try-except blocks for API calls. - Catch appropriate exception types for detailed error reporting. - Some tests deliberately create errors to verify exception handling. ``` -------------------------------- ### Cancel SMS with Netgsm Python SDK Source: https://github.com/netgsm/netgsm-sms-python/blob/main/docs/README.md Allows cancellation of a previously scheduled SMS job. Requires the `jobid` of the SMS to be cancelled. ```python response = netgsm.sms.cancel( jobid="12345678" ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.