From 3509e61adeb10c9d1ddcb75d13c0dd7df67585a2 Mon Sep 17 00:00:00 2001 From: Manisha Singh Date: Fri, 1 Dec 2023 11:06:19 +0530 Subject: [PATCH 01/16] feat: json content type (#737) * feat: add application/json support for client * feat: add application/json support for client * feat: add application/json support for client * feat: add application/json support for client * feat: add application/json support for client --- twilio/http/http_client.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/twilio/http/http_client.py b/twilio/http/http_client.py index bfc38feaf7..7a1715ad49 100644 --- a/twilio/http/http_client.py +++ b/twilio/http/http_client.py @@ -27,11 +27,10 @@ def __init__( ): """ Constructor for the TwilioHttpClient - :param pool_connections :param request_hooks :param timeout: Timeout for the requests. - Timeout should never be zero (0) or less. + Timeout should never be zero (0) or less :param logger :param proxy: Http proxy for the requests session :param max_retries: Maximum number of retries each request should attempt @@ -65,10 +64,10 @@ def request( :param headers: HTTP Headers to send with the request :param auth: Basic Auth arguments :param timeout: Socket/Read timeout for the request - :param allow_redirects: Whether or not to allow redirects + :param allow_redirects: Whether to allow redirects See the requests documentation for explanation of all these parameters - :return: An http response + :return: An HTTP response """ if timeout is None: timeout = self.timeout @@ -79,12 +78,14 @@ def request( "method": method.upper(), "url": url, "params": params, - "data": data, "headers": headers, "auth": auth, "hooks": self.request_hooks, } - + if headers and headers.get("Content-Type") == "application/json": + kwargs["json"] = data + else: + kwargs["data"] = data self.log_request(kwargs) self._test_only_last_response = None From 01077998c7b89449717e2ca34040f7694e2fcb8f Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Wed, 6 Dec 2023 17:57:12 +0530 Subject: [PATCH 02/16] chore: updated changelogs for rc-branch --- CHANGES.md | 4 ++++ UPGRADE.md | 10 ++++++++++ setup.py | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 12b45c6b05..3054ab1962 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,10 @@ twilio-python Changelog Here you can see the full list of changes between each twilio-python release. +[2023-12-06] Version 9.0.0-rc.0 +--------------------------- +- Release Candidate preparation + [2023-11-17] Version 8.10.2 --------------------------- **Library - Chore** diff --git a/UPGRADE.md b/UPGRADE.md index 79bdb48cc5..4bf1602c61 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -3,6 +3,16 @@ _`MAJOR` version bumps will have upgrade notes posted here._ +## [2023-12-06] 8.x.x to 9.x.x-rc.x + +--- +### Overview + +#### Twilio Python Helper Library’s major version 9.0.0-rc.x is now available. We ensured that you can upgrade to Python helper Library 9.0.0-rc.x version without any breaking changes + +Support for JSON payloads has been added in the request body + + ## [2023-04-05] 7.x.x to 8.x.x - **Supported Python versions updated** diff --git a/setup.py b/setup.py index 0c3f8983a8..0ac07a566a 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ setup( name="twilio", - version="8.10.2", + version="9.0.0-rc", description="Twilio API client and TwiML generator", author="Twilio", help_center="https://www.twilio.com/help/contact", From 568048c313d27e8f452798cb80638fb70983fee2 Mon Sep 17 00:00:00 2001 From: Manisha Singh Date: Wed, 13 Dec 2023 18:13:22 +0530 Subject: [PATCH 03/16] chore: add domain detail (#739) * feat: add domain detail to twilio python * feat: add domain detail to twilio python * feat: add domain detail to twilio python * feat: add domain detail to twilio python --- twilio/rest/__init__.py | 15 ++ .../preview_messaging/PreviewMessagingBase.py | 43 ++++ twilio/rest/preview_messaging/__init__.py | 13 + twilio/rest/preview_messaging/v1/__init__.py | 50 ++++ twilio/rest/preview_messaging/v1/broadcast.py | 126 ++++++++++ twilio/rest/preview_messaging/v1/message.py | 237 ++++++++++++++++++ 6 files changed, 484 insertions(+) create mode 100644 twilio/rest/preview_messaging/PreviewMessagingBase.py create mode 100644 twilio/rest/preview_messaging/__init__.py create mode 100644 twilio/rest/preview_messaging/v1/__init__.py create mode 100644 twilio/rest/preview_messaging/v1/broadcast.py create mode 100644 twilio/rest/preview_messaging/v1/message.py diff --git a/twilio/rest/__init__.py b/twilio/rest/__init__.py index 1206b29b0b..044537c41a 100644 --- a/twilio/rest/__init__.py +++ b/twilio/rest/__init__.py @@ -34,6 +34,7 @@ from twilio.rest.notify import Notify from twilio.rest.numbers import Numbers from twilio.rest.preview import Preview + from twilio.rest.preview_messaging import PreviewMessaging from twilio.rest.pricing import Pricing from twilio.rest.proxy import Proxy from twilio.rest.routes import Routes @@ -142,6 +143,7 @@ def __init__( self._notify: Optional["Notify"] = None self._numbers: Optional["Numbers"] = None self._preview: Optional["Preview"] = None + self._preview_messaging: Optional["PreviewMessaging"] = None self._pricing: Optional["Pricing"] = None self._proxy: Optional["Proxy"] = None self._routes: Optional["Routes"] = None @@ -430,6 +432,19 @@ def preview(self) -> "Preview": self._preview = Preview(self) return self._preview + @property + def preview_messaging(self) -> "PreviewMessaging": + """ + Access the Preview Messaging Twilio Domain + + :returns: Preview Messaging Twilio Domain + """ + if self._preview_messaging is None: + from twilio.rest.preview_messaging import PreviewMessaging + + self._preview_messaging = PreviewMessaging(self) + return self._preview_messaging + @property def pricing(self) -> "Pricing": """ diff --git a/twilio/rest/preview_messaging/PreviewMessagingBase.py b/twilio/rest/preview_messaging/PreviewMessagingBase.py new file mode 100644 index 0000000000..3b03fb7c0e --- /dev/null +++ b/twilio/rest/preview_messaging/PreviewMessagingBase.py @@ -0,0 +1,43 @@ +r""" + This code was generated by + ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + + NOTE: This class is auto generated by OpenAPI Generator. + https://openapi-generator.tech + Do not edit the class manually. +""" + +from typing import Optional + +from twilio.base.domain import Domain +from twilio.rest import Client +from twilio.rest.preview_messaging.v1 import V1 + + +class PreviewMessagingBase(Domain): + def __init__(self, twilio: Client): + """ + Initialize the Preview Messaging Domain + + :returns: Domain for Preview Messaging + """ + super().__init__(twilio, "https://preview.messaging.twilio.com") + self._v1: Optional[V1] = None + + @property + def v1(self) -> V1: + """ + :returns: Versions v1 of Preview Messaging + """ + if self._v1 is None: + self._v1 = V1(self) + return self._v1 + + def __repr__(self) -> str: + """ + Provide a friendly representation + :returns: Machine friendly representation + """ + return "" diff --git a/twilio/rest/preview_messaging/__init__.py b/twilio/rest/preview_messaging/__init__.py new file mode 100644 index 0000000000..73bf67969d --- /dev/null +++ b/twilio/rest/preview_messaging/__init__.py @@ -0,0 +1,13 @@ +from twilio.rest.preview_messaging.PreviewMessagingBase import PreviewMessagingBase +from twilio.rest.preview_messaging.v1.broadcast import BroadcastList +from twilio.rest.preview_messaging.v1.message import MessageList + + +class PreviewMessaging(PreviewMessagingBase): + @property + def broadcast(self) -> BroadcastList: + return self.v1.broadcasts + + @property + def messages(self) -> MessageList: + return self.v1.messages diff --git a/twilio/rest/preview_messaging/v1/__init__.py b/twilio/rest/preview_messaging/v1/__init__.py new file mode 100644 index 0000000000..0e1e182d49 --- /dev/null +++ b/twilio/rest/preview_messaging/v1/__init__.py @@ -0,0 +1,50 @@ +r""" + This code was generated by + ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + + Bulk Messaging and Broadcast + Bulk Sending is a public Twilio REST API for 1:Many Message creation up to 100 recipients. Broadcast is a public Twilio REST API for 1:Many Message creation up to 10,000 recipients via file upload. + + NOTE: This class is auto generated by OpenAPI Generator. + https://openapi-generator.tech + Do not edit the class manually. +""" + +from typing import Optional +from twilio.base.version import Version +from twilio.base.domain import Domain +from twilio.rest.preview_messaging.v1.broadcast import BroadcastList +from twilio.rest.preview_messaging.v1.message import MessageList + + +class V1(Version): + def __init__(self, domain: Domain): + """ + Initialize the V1 version of PreviewMessaging + + :param domain: The Twilio.preview_messaging domain + """ + super().__init__(domain, "v1") + self._broadcasts: Optional[BroadcastList] = None + self._messages: Optional[MessageList] = None + + @property + def broadcasts(self) -> BroadcastList: + if self._broadcasts is None: + self._broadcasts = BroadcastList(self) + return self._broadcasts + + @property + def messages(self) -> MessageList: + if self._messages is None: + self._messages = MessageList(self) + return self._messages + + def __repr__(self) -> str: + """ + Provide a friendly representation + :returns: Machine friendly representation + """ + return "" diff --git a/twilio/rest/preview_messaging/v1/broadcast.py b/twilio/rest/preview_messaging/v1/broadcast.py new file mode 100644 index 0000000000..3c8e1819d6 --- /dev/null +++ b/twilio/rest/preview_messaging/v1/broadcast.py @@ -0,0 +1,126 @@ +r""" + This code was generated by + ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + + Bulk Messaging and Broadcast + Bulk Sending is a public Twilio REST API for 1:Many Message creation up to 100 recipients. Broadcast is a public Twilio REST API for 1:Many Message creation up to 10,000 recipients via file upload. + + NOTE: This class is auto generated by OpenAPI Generator. + https://openapi-generator.tech + Do not edit the class manually. +""" + + +from datetime import datetime +from typing import Any, Dict, Optional, Union +from twilio.base import deserialize, values + +from twilio.base.instance_resource import InstanceResource +from twilio.base.list_resource import ListResource +from twilio.base.version import Version + + +class BroadcastInstance(InstanceResource): + + """ + :ivar broadcast_sid: Numeric ID indentifying individual Broadcast requests + :ivar created_date: Timestamp of when the Broadcast was created + :ivar updated_date: Timestamp of when the Broadcast was last updated + :ivar broadcast_status: Status of the Broadcast request. Valid values are None, Pending-Upload, Uploaded, Queued, Executing, Execution-Failure, Execution-Completed, Cancelation-Requested, and Canceled + :ivar execution_details: + :ivar results_file: Path to a file detailing successful requests and errors from Broadcast execution + """ + + def __init__(self, version: Version, payload: Dict[str, Any]): + super().__init__(version) + + self.broadcast_sid: Optional[str] = payload.get("broadcast_sid") + self.created_date: Optional[datetime] = deserialize.iso8601_datetime( + payload.get("created_date") + ) + self.updated_date: Optional[datetime] = deserialize.iso8601_datetime( + payload.get("updated_date") + ) + self.broadcast_status: Optional[str] = payload.get("broadcast_status") + self.execution_details: Optional[str] = payload.get("execution_details") + self.results_file: Optional[str] = payload.get("results_file") + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + + return "" + + +class BroadcastList(ListResource): + def __init__(self, version: Version): + """ + Initialize the BroadcastList + + :param version: Version that contains the resource + + """ + super().__init__(version) + + self._uri = "/Broadcasts" + + def create( + self, x_twilio_request_key: Union[str, object] = values.unset + ) -> BroadcastInstance: + """ + Create the BroadcastInstance + + :param x_twilio_request_key: Idempotency key provided by the client + + :returns: The created BroadcastInstance + """ + + data = values.of({}) + headers = values.of( + { + "X-Twilio-Request-Key": x_twilio_request_key, + } + ) + + payload = self._version.create( + method="POST", uri=self._uri, data=data, headers=headers + ) + + return BroadcastInstance(self._version, payload) + + async def create_async( + self, x_twilio_request_key: Union[str, object] = values.unset + ) -> BroadcastInstance: + """ + Asynchronously create the BroadcastInstance + + :param x_twilio_request_key: Idempotency key provided by the client + + :returns: The created BroadcastInstance + """ + + data = values.of({}) + headers = values.of( + { + "X-Twilio-Request-Key": x_twilio_request_key, + } + ) + + payload = await self._version.create_async( + method="POST", uri=self._uri, data=data, headers=headers + ) + + return BroadcastInstance(self._version, payload) + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + return "" diff --git a/twilio/rest/preview_messaging/v1/message.py b/twilio/rest/preview_messaging/v1/message.py new file mode 100644 index 0000000000..2d83b93382 --- /dev/null +++ b/twilio/rest/preview_messaging/v1/message.py @@ -0,0 +1,237 @@ +r""" + This code was generated by + ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + + Bulk Messaging and Broadcast + Bulk Sending is a public Twilio REST API for 1:Many Message creation up to 100 recipients. Broadcast is a public Twilio REST API for 1:Many Message creation up to 10,000 recipients via file upload. + + NOTE: This class is auto generated by OpenAPI Generator. + https://openapi-generator.tech + Do not edit the class manually. +""" + + +from typing import Any, Dict, List, Optional +from twilio.base import deserialize + +from twilio.base.instance_resource import InstanceResource +from twilio.base.list_resource import ListResource +from twilio.base.version import Version + + +class MessageInstance(InstanceResource): + + """ + :ivar total_message_count: The number of Messages processed in the request, equal to the sum of success_count and error_count. + :ivar success_count: The number of Messages successfully created. + :ivar error_count: The number of Messages unsuccessfully processed in the request. + :ivar message_receipts: + :ivar failed_message_receipts: + """ + + def __init__(self, version: Version, payload: Dict[str, Any]): + super().__init__(version) + + self.total_message_count: Optional[int] = deserialize.integer( + payload.get("total_message_count") + ) + self.success_count: Optional[int] = deserialize.integer( + payload.get("success_count") + ) + self.error_count: Optional[int] = deserialize.integer( + payload.get("error_count") + ) + self.message_receipts: Optional[List[str]] = payload.get("message_receipts") + self.failed_message_receipts: Optional[List[str]] = payload.get( + "failed_message_receipts" + ) + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + + return "" + + +class MessageList(ListResource): + class CreateMessagesRequest(object): + """ + :ivar messages: + :ivar from_: A Twilio phone number in [E.164](https://www.twilio.com/docs/glossary/what-e164) format, an [alphanumeric sender ID](https://www.twilio.com/docs/sms/send-messages#use-an-alphanumeric-sender-id), or a [Channel Endpoint address](https://www.twilio.com/docs/sms/channels#channel-addresses) that is enabled for the type of message you want to send. Phone numbers or [short codes](https://www.twilio.com/docs/sms/api/short-code) purchased from Twilio also work here. You cannot, for example, spoof messages from a private cell phone number. If you are using `messaging_service_sid`, this parameter must be empty. + :ivar messaging_service_sid: The SID of the [Messaging Service](https://www.twilio.com/docs/sms/services#send-a-message-with-copilot) you want to associate with the Message. Set this parameter to use the [Messaging Service Settings and Copilot Features](https://www.twilio.com/console/sms/services) you have configured and leave the `from` parameter empty. When only this parameter is set, Twilio will use your enabled Copilot Features to select the `from` phone number for delivery. + :ivar body: The text of the message you want to send. Can be up to 1,600 characters in length. + :ivar content_sid: The SID of the preconfigured [Content Template](https://www.twilio.com/docs/content-api/create-and-send-your-first-content-api-template#create-a-template) you want to associate with the Message. Must be used in conjuction with a preconfigured [Messaging Service Settings and Copilot Features](https://www.twilio.com/console/sms/services) When this parameter is set, Twilio will use your configured content template and the provided `ContentVariables`. This Twilio product is currently in Private Beta. + :ivar media_url: The URL of the media to send with the message. The media can be of type `gif`, `png`, and `jpeg` and will be formatted correctly on the recipient's device. The media size limit is 5MB for supported file types (JPEG, PNG, GIF) and 500KB for [other types](https://www.twilio.com/docs/sms/accepted-mime-types) of accepted media. To send more than one image in the message body, provide multiple `media_url` parameters in the POST request. You can include up to 10 `media_url` parameters per message. You can send images in an SMS message in only the US and Canada. + :ivar status_callback: The URL we should call using the \"status_callback_method\" to send status information to your application. If specified, we POST these message status changes to the URL - queued, failed, sent, delivered, or undelivered. Twilio will POST its [standard request parameters](https://www.twilio.com/docs/messaging/twiml#request-parameters) as well as some additional parameters including \"MessageSid\", \"MessageStatus\", and \"ErrorCode\". If you include this parameter with the \"messaging_service_sid\", we use this URL instead of the Status Callback URL of the [Messaging Service](https://www.twilio.com/docs/messaging/services/api). URLs must contain a valid hostname and underscores are not allowed. + :ivar validity_period: How long in seconds the message can remain in our outgoing message queue. After this period elapses, the message fails and we call your status callback. Can be between 1 and the default value of 14,400 seconds. After a message has been accepted by a carrier, however, we cannot guarantee that the message will not be queued after this period. We recommend that this value be at least 5 seconds. + :ivar send_at: The time at which Twilio will send the message. This parameter can be used to schedule a message to be sent at a particular time. Must be in ISO 8601 format. + :ivar schedule_type: This parameter indicates your intent to schedule a message. Pass the value `fixed` to schedule a message at a fixed time. This parameter works in conjuction with the `SendAt` parameter. + :ivar shorten_urls: Determines the usage of Click Tracking. Setting it to `true` will instruct Twilio to replace all links in the Message with a shortened version based on the associated Domain Sid and track clicks on them. If this parameter is not set on an API call, we will use the value set on the Messaging Service. If this parameter is not set and the value is not configured on the Messaging Service used this will default to `false`. + :ivar send_as_mms: If set to True, Twilio will deliver the message as a single MMS message, regardless of the presence of media. + :ivar max_price: The maximum total price in US dollars that you will pay for the message to be delivered. Can be a decimal value that has up to 4 decimal places. All messages are queued for delivery and the message cost is checked before the message is sent. If the cost exceeds max_price, the message will fail and a status of Failed is sent to the status callback. If MaxPrice is not set, the message cost is not checked. + :ivar attempt: Total number of attempts made ( including this ) to send out the message regardless of the provider used + :ivar smart_encoded: This parameter indicates whether to detect Unicode characters that have a similar GSM-7 character and replace them. Can be true or false. + :ivar force_delivery: This parameter allows Twilio to send SMS traffic to carriers without checking/caring whether the destination number is a mobile or a landline. + :ivar application_sid: The SID of the application that should receive message status. We POST a message_sid parameter and a message_status parameter with a value of sent or failed to the application's message_status_callback. If a status_callback parameter is also passed, it will be ignored and the application's message_status_callback parameter will be used. + """ + + def __init__(self, payload: Dict[str, Any]): + self.messages: Optional[MessageList.MessagingV1Message] = payload.get( + "messages" + ) + self.from_: Optional[str] = payload.get("from_") + self.messaging_service_sid: Optional[str] = payload.get( + "messaging_service_sid" + ) + self.body: Optional[str] = payload.get("body") + self.content_sid: Optional[str] = payload.get("content_sid") + self.media_url: Optional[str] = payload.get("media_url") + self.status_callback: Optional[str] = payload.get("status_callback") + self.validity_period: Optional[int] = payload.get("validity_period") + self.send_at: Optional[str] = payload.get("send_at") + self.schedule_type: Optional[str] = payload.get("schedule_type") + self.shorten_urls: Optional[bool] = payload.get("shorten_urls") + self.send_as_mms: Optional[bool] = payload.get("send_as_mms") + self.max_price: Optional[float] = payload.get("max_price") + self.attempt: Optional[int] = payload.get("attempt") + self.smart_encoded: Optional[bool] = payload.get("smart_encoded") + self.force_delivery: Optional[bool] = payload.get("force_delivery") + self.application_sid: Optional[str] = payload.get("application_sid") + + def to_dict(self): + return { + "messages": [messages.to_dict() for messages in self.messages], + "from": self.from_, + "messaging_service_sid": self.messaging_service_sid, + "body": self.body, + "content_sid": self.content_sid, + "media_url": self.media_url, + "status_callback": self.status_callback, + "validity_period": self.validity_period, + "send_at": self.send_at, + "schedule_type": self.schedule_type, + "shorten_urls": self.shorten_urls, + "send_as_mms": self.send_as_mms, + "max_price": self.max_price, + "attempt": self.attempt, + "smart_encoded": self.smart_encoded, + "force_delivery": self.force_delivery, + "application_sid": self.application_sid, + } + + class MessagingV1FailedMessageReceipt(object): + """ + :ivar to: The recipient phone number + :ivar error_message: The description of the error_code + :ivar error_code: The error code associated with the message creation attempt + """ + + def __init__(self, payload: Dict[str, Any]): + self.to: Optional[str] = payload.get("to") + self.error_message: Optional[str] = payload.get("error_message") + self.error_code: Optional[int] = payload.get("error_code") + + def to_dict(self): + return { + "to": self.to, + "error_message": self.error_message, + "error_code": self.error_code, + } + + class MessagingV1Message(object): + """ + :ivar to: The destination phone number in [E.164](https://www.twilio.com/docs/glossary/what-e164) format for SMS/MMS or [Channel user address](https://www.twilio.com/docs/sms/channels#channel-addresses) for other 3rd-party channels. + :ivar body: The text of the message you want to send. Can be up to 1,600 characters in length. Overrides the request-level body and content template if provided. + :ivar content_variables: Key-value pairs of variable names to substitution values. Refer to the [Twilio Content API Resources](https://www.twilio.com/docs/content-api/content-api-resources#send-a-message-with-preconfigured-content) for more details. + """ + + def __init__(self, payload: Dict[str, Any]): + self.to: Optional[str] = payload.get("to") + self.body: Optional[str] = payload.get("body") + self.content_variables: Optional[dict[str, str]] = payload.get( + "content_variables" + ) + + def to_dict(self): + return { + "to": self.to, + "body": self.body, + "content_variables": self.content_variables, + } + + class MessagingV1MessageReceipt(object): + """ + :ivar to: The recipient phone number + :ivar sid: The unique string that identifies the resource + """ + + def __init__(self, payload: Dict[str, Any]): + self.to: Optional[str] = payload.get("to") + self.sid: Optional[str] = payload.get("sid") + + def to_dict(self): + return { + "to": self.to, + "sid": self.sid, + } + + def __init__(self, version: Version): + """ + Initialize the MessageList + + :param version: Version that contains the resource + + """ + super().__init__(version) + + self._uri = "/Messages" + + def create(self, create_messages_request: CreateMessagesRequest) -> MessageInstance: + """ + Create the MessageInstance + + :param create_messages_request: + + :returns: The created MessageInstance + """ + data = create_messages_request.to_dict() + + headers = {"Content-Type": "application/json"} + payload = self._version.create( + method="POST", uri=self._uri, data=data, headers=headers + ) + + return MessageInstance(self._version, payload) + + async def create_async( + self, create_messages_request: CreateMessagesRequest + ) -> MessageInstance: + """ + Asynchronously create the MessageInstance + + :param create_messages_request: + + :returns: The created MessageInstance + """ + + data = create_messages_request.to_dict() + headers = {"Content-Type": "application/json"} + + payload = await self._version.create_async( + method="POST", uri=self._uri, data=data, headers=headers + ) + + return MessageInstance(self._version, payload) + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + return "" From 343a3b22a1a3c4e70f092595e597b21f1e2f5aa5 Mon Sep 17 00:00:00 2001 From: sbansla Date: Thu, 4 Jan 2024 14:08:40 +0530 Subject: [PATCH 04/16] corrected rc version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0ac07a566a..a4708e3d57 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ setup( name="twilio", - version="9.0.0-rc", + version="9.0.0-rc.0", description="Twilio API client and TwiML generator", author="Twilio", help_center="https://www.twilio.com/help/contact", From 22c6cb0e35ab68249f4c81aabce97354e11d5d1c Mon Sep 17 00:00:00 2001 From: Shubham Date: Thu, 4 Jan 2024 15:32:23 +0530 Subject: [PATCH 05/16] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a4708e3d57..12c0b48339 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ setup( name="twilio", - version="9.0.0-rc.0", + version="9.0.0-rc.0", description="Twilio API client and TwiML generator", author="Twilio", help_center="https://www.twilio.com/help/contact", From 5a4bddc9999904a3d5c93a47bab593bae5386ee6 Mon Sep 17 00:00:00 2001 From: Shubham Date: Thu, 4 Jan 2024 15:35:06 +0530 Subject: [PATCH 06/16] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 12c0b48339..a4708e3d57 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ setup( name="twilio", - version="9.0.0-rc.0", + version="9.0.0-rc.0", description="Twilio API client and TwiML generator", author="Twilio", help_center="https://www.twilio.com/help/contact", From 399e1e34a27931d05a1f2648c5e3fab191b3d51c Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Mon, 8 Jan 2024 12:56:42 +0530 Subject: [PATCH 07/16] chore: corrected cluster test --- tests/cluster/test_webhook.py | 163 ++++++++++++++++------------------ 1 file changed, 79 insertions(+), 84 deletions(-) diff --git a/tests/cluster/test_webhook.py b/tests/cluster/test_webhook.py index 37c0dda3b1..307cf3d397 100644 --- a/tests/cluster/test_webhook.py +++ b/tests/cluster/test_webhook.py @@ -1,12 +1,7 @@ import os -import unittest -import time -import _thread -from http.server import BaseHTTPRequestHandler, HTTPServer -from pyngrok import ngrok +from http.server import BaseHTTPRequestHandler from twilio.request_validator import RequestValidator -from twilio.rest import Client class RequestHandler(BaseHTTPRequestHandler): @@ -34,81 +29,81 @@ def process_request(self): ) -class WebhookTest(unittest.TestCase): - def setUp(self): - api_key = os.environ["TWILIO_API_KEY"] - api_secret = os.environ["TWILIO_API_SECRET"] - account_sid = os.environ["TWILIO_ACCOUNT_SID"] - self.client = Client(api_key, api_secret, account_sid) - - portNumber = 7777 - self.validation_server = HTTPServer(("", portNumber), RequestHandler) - self.tunnel = ngrok.connect(portNumber) - self.flow_sid = "" - _thread.start_new_thread(self.start_http_server, ()) - - def start_http_server(self): - self.validation_server.serve_forever() - - def tearDown(self): - self.client.studio.v2.flows(self.flow_sid).delete() - ngrok.kill() - self.validation_server.shutdown() - self.validation_server.server_close() - - def create_studio_flow(self, url, method): - flow = self.client.studio.v2.flows.create( - friendly_name="Python Cluster Test Flow", - status="published", - definition={ - "description": "Studio Flow", - "states": [ - { - "name": "Trigger", - "type": "trigger", - "transitions": [ - { - "next": "httpRequest", - "event": "incomingRequest", - }, - ], - "properties": {}, - }, - { - "name": "httpRequest", - "type": "make-http-request", - "transitions": [], - "properties": { - "method": method, - "content_type": "application/x-www-form-urlencoded;charset=utf-8", - "url": url, - }, - }, - ], - "initial_state": "Trigger", - "flags": { - "allow_concurrent_calls": True, - }, - }, - ) - return flow - - def validate(self, method): - flow = self.create_studio_flow(url=self.tunnel.public_url, method=method) - self.flow_sid = flow.sid - time.sleep(5) - self.client.studio.v2.flows(self.flow_sid).executions.create( - to="to", from_="from" - ) - - def test_get(self): - time.sleep(5) - self.validate("GET") - time.sleep(5) - self.assertEqual(RequestHandler.is_request_valid, True) - - def test_post(self): - time.sleep(5) - self.validate("POST") - time.sleep(5) - self.assertEqual(RequestHandler.is_request_valid, True) +# class WebhookTest(unittest.TestCase): +# def setUp(self): +# api_key = os.environ["TWILIO_API_KEY"] +# api_secret = os.environ["TWILIO_API_SECRET"] +# account_sid = os.environ["TWILIO_ACCOUNT_SID"] +# self.client = Client(api_key, api_secret, account_sid) +# +# portNumber = 7777 +# self.validation_server = HTTPServer(("", portNumber), RequestHandler) +# self.tunnel = ngrok.connect(portNumber) +# self.flow_sid = "" +# _thread.start_new_thread(self.start_http_server, ()) +# +# def start_http_server(self): +# self.validation_server.serve_forever() +# +# def tearDown(self): +# self.client.studio.v2.flows(self.flow_sid).delete() +# ngrok.kill() +# self.validation_server.shutdown() +# self.validation_server.server_close() +# +# def create_studio_flow(self, url, method): +# flow = self.client.studio.v2.flows.create( +# friendly_name="Python Cluster Test Flow", +# status="published", +# definition={ +# "description": "Studio Flow", +# "states": [ +# { +# "name": "Trigger", +# "type": "trigger", +# "transitions": [ +# { +# "next": "httpRequest", +# "event": "incomingRequest", +# }, +# ], +# "properties": {}, +# }, +# { +# "name": "httpRequest", +# "type": "make-http-request", +# "transitions": [], +# "properties": { +# "method": method, +# "content_type": "application/x-www-form-urlencoded;charset=utf-8", +# "url": url, +# }, +# }, +# ], +# "initial_state": "Trigger", +# "flags": { +# "allow_concurrent_calls": True, +# }, +# }, +# ) +# return flow +# +# def validate(self, method): +# flow = self.create_studio_flow(url=self.tunnel.public_url, method=method) +# self.flow_sid = flow.sid +# time.sleep(5) +# self.client.studio.v2.flows(self.flow_sid).executions.create( +# to="to", from_="from" +# ) +# +# def test_get(self): +# time.sleep(5) +# self.validate("GET") +# time.sleep(5) +# self.assertEqual(RequestHandler.is_request_valid, True) +# +# def test_post(self): +# time.sleep(5) +# self.validate("POST") +# time.sleep(5) +# self.assertEqual(RequestHandler.is_request_valid, True) From 4f1d5d3929b16c2e7275b6969feacc3f50286311 Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Mon, 8 Jan 2024 13:44:49 +0530 Subject: [PATCH 08/16] chore: using jprq instead of ngrok --- requirements.txt | 1 + tests/cluster/test_webhook.py | 164 ++++++++++++++++++---------------- 2 files changed, 86 insertions(+), 79 deletions(-) diff --git a/requirements.txt b/requirements.txt index f2b815e854..6643c526e2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ requests>=2.0.0 PyJWT>=2.0.0, <3.0.0 aiohttp>=3.9.0 aiohttp-retry>=2.8.3 +jprq diff --git a/tests/cluster/test_webhook.py b/tests/cluster/test_webhook.py index 307cf3d397..241802f805 100644 --- a/tests/cluster/test_webhook.py +++ b/tests/cluster/test_webhook.py @@ -1,7 +1,12 @@ import os +import unittest +import time +import _thread +import subprocess -from http.server import BaseHTTPRequestHandler +from http.server import BaseHTTPRequestHandler, HTTPServer from twilio.request_validator import RequestValidator +from twilio.rest import Client class RequestHandler(BaseHTTPRequestHandler): @@ -29,81 +34,82 @@ def process_request(self): ) -# class WebhookTest(unittest.TestCase): -# def setUp(self): -# api_key = os.environ["TWILIO_API_KEY"] -# api_secret = os.environ["TWILIO_API_SECRET"] -# account_sid = os.environ["TWILIO_ACCOUNT_SID"] -# self.client = Client(api_key, api_secret, account_sid) -# -# portNumber = 7777 -# self.validation_server = HTTPServer(("", portNumber), RequestHandler) -# self.tunnel = ngrok.connect(portNumber) -# self.flow_sid = "" -# _thread.start_new_thread(self.start_http_server, ()) -# -# def start_http_server(self): -# self.validation_server.serve_forever() -# -# def tearDown(self): -# self.client.studio.v2.flows(self.flow_sid).delete() -# ngrok.kill() -# self.validation_server.shutdown() -# self.validation_server.server_close() -# -# def create_studio_flow(self, url, method): -# flow = self.client.studio.v2.flows.create( -# friendly_name="Python Cluster Test Flow", -# status="published", -# definition={ -# "description": "Studio Flow", -# "states": [ -# { -# "name": "Trigger", -# "type": "trigger", -# "transitions": [ -# { -# "next": "httpRequest", -# "event": "incomingRequest", -# }, -# ], -# "properties": {}, -# }, -# { -# "name": "httpRequest", -# "type": "make-http-request", -# "transitions": [], -# "properties": { -# "method": method, -# "content_type": "application/x-www-form-urlencoded;charset=utf-8", -# "url": url, -# }, -# }, -# ], -# "initial_state": "Trigger", -# "flags": { -# "allow_concurrent_calls": True, -# }, -# }, -# ) -# return flow -# -# def validate(self, method): -# flow = self.create_studio_flow(url=self.tunnel.public_url, method=method) -# self.flow_sid = flow.sid -# time.sleep(5) -# self.client.studio.v2.flows(self.flow_sid).executions.create( -# to="to", from_="from" -# ) -# -# def test_get(self): -# time.sleep(5) -# self.validate("GET") -# time.sleep(5) -# self.assertEqual(RequestHandler.is_request_valid, True) -# -# def test_post(self): -# time.sleep(5) -# self.validate("POST") -# time.sleep(5) -# self.assertEqual(RequestHandler.is_request_valid, True) +class WebhookTest(unittest.TestCase): + def setUp(self): + api_key = os.environ["TWILIO_API_KEY"] + api_secret = os.environ["TWILIO_API_SECRET"] + account_sid = os.environ["TWILIO_ACCOUNT_SID"] + self.client = Client(api_key, api_secret, account_sid) + + port_number = 7777 + self.validation_server = HTTPServer(("", port_number), RequestHandler) + self.tunnel = subprocess.Popen(["jprq", "http", port_number]) + self.tunnel_url = self.tunnel.stdout.readline().decode().strip() # Capture the URL + self.flow_sid = "" + _thread.start_new_thread(self.start_http_server, ()) + + def start_http_server(self): + self.validation_server.serve_forever() + + def tearDown(self): + self.client.studio.v2.flows(self.flow_sid).delete() + self.tunnel.kill() + self.validation_server.shutdown() + self.validation_server.server_close() + + def create_studio_flow(self, url, method): + flow = self.client.studio.v2.flows.create( + friendly_name="Python Cluster Test Flow", + status="published", + definition={ + "description": "Studio Flow", + "states": [ + { + "name": "Trigger", + "type": "trigger", + "transitions": [ + { + "next": "httpRequest", + "event": "incomingRequest", + }, + ], + "properties": {}, + }, + { + "name": "httpRequest", + "type": "make-http-request", + "transitions": [], + "properties": { + "method": method, + "content_type": "application/x-www-form-urlencoded;charset=utf-8", + "url": url, + }, + }, + ], + "initial_state": "Trigger", + "flags": { + "allow_concurrent_calls": True, + }, + }, + ) + return flow + + def validate(self, method): + flow = self.create_studio_flow(url=self.tunnel.public_url, method=method) + self.flow_sid = flow.sid + time.sleep(5) + self.client.studio.v2.flows(self.flow_sid).executions.create( + to="to", from_="from" + ) + + def test_get(self): + time.sleep(5) + self.validate("GET") + time.sleep(5) + self.assertEqual(RequestHandler.is_request_valid, True) + + def test_post(self): + time.sleep(5) + self.validate("POST") + time.sleep(5) + self.assertEqual(RequestHandler.is_request_valid, True) From bd0c7aa1c44f3e0e18bf0f75248032719dcb61e0 Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Mon, 8 Jan 2024 13:47:15 +0530 Subject: [PATCH 09/16] chore: prettier check --- tests/cluster/test_webhook.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/cluster/test_webhook.py b/tests/cluster/test_webhook.py index 241802f805..ff7b415f39 100644 --- a/tests/cluster/test_webhook.py +++ b/tests/cluster/test_webhook.py @@ -44,7 +44,9 @@ def setUp(self): port_number = 7777 self.validation_server = HTTPServer(("", port_number), RequestHandler) self.tunnel = subprocess.Popen(["jprq", "http", port_number]) - self.tunnel_url = self.tunnel.stdout.readline().decode().strip() # Capture the URL + self.tunnel_url = ( + self.tunnel.stdout.readline().decode().strip() + ) # Capture the URL self.flow_sid = "" _thread.start_new_thread(self.start_http_server, ()) From 66624befbac52f39dec438b7109214dc2831339c Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Mon, 8 Jan 2024 14:25:48 +0530 Subject: [PATCH 10/16] chore: correcting use of jprq instead of ngrok --- requirements.txt | 1 - tests/cluster/test_webhook.py | 2 +- tests/requirements.txt | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 6643c526e2..f2b815e854 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,3 @@ requests>=2.0.0 PyJWT>=2.0.0, <3.0.0 aiohttp>=3.9.0 aiohttp-retry>=2.8.3 -jprq diff --git a/tests/cluster/test_webhook.py b/tests/cluster/test_webhook.py index ff7b415f39..0924c81935 100644 --- a/tests/cluster/test_webhook.py +++ b/tests/cluster/test_webhook.py @@ -43,7 +43,7 @@ def setUp(self): port_number = 7777 self.validation_server = HTTPServer(("", port_number), RequestHandler) - self.tunnel = subprocess.Popen(["jprq", "http", port_number]) + self.tunnel = subprocess.Popen(["jprq", "http", str(port_number)]) self.tunnel_url = ( self.tunnel.stdout.readline().decode().strip() ) # Capture the URL diff --git a/tests/requirements.txt b/tests/requirements.txt index 679f8e13d0..ac6766a507 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -9,6 +9,6 @@ cryptography recommonmark django multidict -pyngrok black autoflake +jprq From fda3a53c87ffa85b20dfdc7b60a34fce6975d755 Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Mon, 8 Jan 2024 14:32:10 +0530 Subject: [PATCH 11/16] chore: added debug statement --- tests/cluster/test_webhook.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/cluster/test_webhook.py b/tests/cluster/test_webhook.py index 0924c81935..3af5fd7a1d 100644 --- a/tests/cluster/test_webhook.py +++ b/tests/cluster/test_webhook.py @@ -44,6 +44,9 @@ def setUp(self): port_number = 7777 self.validation_server = HTTPServer(("", port_number), RequestHandler) self.tunnel = subprocess.Popen(["jprq", "http", str(port_number)]) + print(self.tunnel.stderr.read()) + if self.tunnel.returncode: + raise Exception("JPRQ failed to start") self.tunnel_url = ( self.tunnel.stdout.readline().decode().strip() ) # Capture the URL From 96391ec9db6655cf8033270c2bbeed81d81b8c53 Mon Sep 17 00:00:00 2001 From: Shubham Date: Mon, 8 Jan 2024 14:44:11 +0530 Subject: [PATCH 12/16] Update test_webhook.py --- tests/cluster/test_webhook.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/cluster/test_webhook.py b/tests/cluster/test_webhook.py index 3af5fd7a1d..946ef888f7 100644 --- a/tests/cluster/test_webhook.py +++ b/tests/cluster/test_webhook.py @@ -44,9 +44,8 @@ def setUp(self): port_number = 7777 self.validation_server = HTTPServer(("", port_number), RequestHandler) self.tunnel = subprocess.Popen(["jprq", "http", str(port_number)]) - print(self.tunnel.stderr.read()) - if self.tunnel.returncode: - raise Exception("JPRQ failed to start") + print(self.tunnel.stderr) + print(self.tunnel.stdout) self.tunnel_url = ( self.tunnel.stdout.readline().decode().strip() ) # Capture the URL From 164fbeda36f35b2878583a215a5a0c34517b8a54 Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Mon, 8 Jan 2024 17:35:32 +0530 Subject: [PATCH 13/16] chore: using py-localtunnel instead of ngrok --- tests/cluster/test_webhook.py | 13 ++++--------- tests/requirements.txt | 2 +- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/tests/cluster/test_webhook.py b/tests/cluster/test_webhook.py index 3af5fd7a1d..6158e4829f 100644 --- a/tests/cluster/test_webhook.py +++ b/tests/cluster/test_webhook.py @@ -2,9 +2,9 @@ import unittest import time import _thread -import subprocess from http.server import BaseHTTPRequestHandler, HTTPServer +from py_localtunnel import LocalTunnel from twilio.request_validator import RequestValidator from twilio.rest import Client @@ -43,13 +43,8 @@ def setUp(self): port_number = 7777 self.validation_server = HTTPServer(("", port_number), RequestHandler) - self.tunnel = subprocess.Popen(["jprq", "http", str(port_number)]) - print(self.tunnel.stderr.read()) - if self.tunnel.returncode: - raise Exception("JPRQ failed to start") - self.tunnel_url = ( - self.tunnel.stdout.readline().decode().strip() - ) # Capture the URL + self.tunnel = LocalTunnel(port=port_number) + self.tunnel.start() self.flow_sid = "" _thread.start_new_thread(self.start_http_server, ()) @@ -58,7 +53,7 @@ def start_http_server(self): def tearDown(self): self.client.studio.v2.flows(self.flow_sid).delete() - self.tunnel.kill() + self.tunnel.stop() self.validation_server.shutdown() self.validation_server.server_close() diff --git a/tests/requirements.txt b/tests/requirements.txt index ac6766a507..486888bba9 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -11,4 +11,4 @@ django multidict black autoflake -jprq +py-localtunnel From bf27f5fa9285a2c641647f7c6194830d07e54e56 Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Mon, 8 Jan 2024 17:46:46 +0530 Subject: [PATCH 14/16] chore: correcting the use of local tunnel --- tests/cluster/test_webhook.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/cluster/test_webhook.py b/tests/cluster/test_webhook.py index 6158e4829f..53e3173997 100644 --- a/tests/cluster/test_webhook.py +++ b/tests/cluster/test_webhook.py @@ -4,7 +4,7 @@ import _thread from http.server import BaseHTTPRequestHandler, HTTPServer -from py_localtunnel import LocalTunnel +from py_localtunnel.tunnel import Tunnel from twilio.request_validator import RequestValidator from twilio.rest import Client @@ -43,8 +43,9 @@ def setUp(self): port_number = 7777 self.validation_server = HTTPServer(("", port_number), RequestHandler) - self.tunnel = LocalTunnel(port=port_number) - self.tunnel.start() + self.tunnel = Tunnel() + self.public_url = self.tunnel.get_url() + self.tunnel.create_tunnel(port=port_number) self.flow_sid = "" _thread.start_new_thread(self.start_http_server, ()) @@ -53,7 +54,7 @@ def start_http_server(self): def tearDown(self): self.client.studio.v2.flows(self.flow_sid).delete() - self.tunnel.stop() + self.tunnel.stop_tunnel() self.validation_server.shutdown() self.validation_server.server_close() @@ -95,7 +96,7 @@ def create_studio_flow(self, url, method): return flow def validate(self, method): - flow = self.create_studio_flow(url=self.tunnel.public_url, method=method) + flow = self.create_studio_flow(url=self.public_url, method=method) self.flow_sid = flow.sid time.sleep(5) self.client.studio.v2.flows(self.flow_sid).executions.create( From 258c73e642e5859f30c3bd42b7ac39e309156401 Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Mon, 8 Jan 2024 18:17:05 +0530 Subject: [PATCH 15/16] chore: adding debug statement in localtunnel --- tests/cluster/test_webhook.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/cluster/test_webhook.py b/tests/cluster/test_webhook.py index 53e3173997..048f2111cf 100644 --- a/tests/cluster/test_webhook.py +++ b/tests/cluster/test_webhook.py @@ -44,8 +44,9 @@ def setUp(self): port_number = 7777 self.validation_server = HTTPServer(("", port_number), RequestHandler) self.tunnel = Tunnel() - self.public_url = self.tunnel.get_url() - self.tunnel.create_tunnel(port=port_number) + self.public_url = self.tunnel.get_url(None) + print('public url ------ ' + self.public_url) + self.tunnel.create_tunnel(port_number) self.flow_sid = "" _thread.start_new_thread(self.start_http_server, ()) From 3d9bac580a2a311e494f5c7a4463485815ce602e Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Mon, 8 Jan 2024 18:19:47 +0530 Subject: [PATCH 16/16] chore: prettier check --- tests/cluster/test_webhook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cluster/test_webhook.py b/tests/cluster/test_webhook.py index 048f2111cf..fce2e37222 100644 --- a/tests/cluster/test_webhook.py +++ b/tests/cluster/test_webhook.py @@ -45,7 +45,7 @@ def setUp(self): self.validation_server = HTTPServer(("", port_number), RequestHandler) self.tunnel = Tunnel() self.public_url = self.tunnel.get_url(None) - print('public url ------ ' + self.public_url) + print("public url ------ " + self.public_url) self.tunnel.create_tunnel(port_number) self.flow_sid = "" _thread.start_new_thread(self.start_http_server, ())