• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.http_request函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中vumi.utils.http_request函数的典型用法代码示例。如果您正苦于以下问题:Python http_request函数的具体用法?Python http_request怎么用?Python http_request使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了http_request函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: search

    def search(self, query, limit=10, namespace=0):
        """
        Perform a query and returns a list of dictionaries with results
        matching the query.

        Parameters
        ----------
        query : str
            The search term.
        limit : int, optional
            How many results to get back, defaults to 10
        namespace : int, optional
            The namespace of the OpenSearch Suggestions extention, defaults
            to 0
        """
        query_params = {
            'search': query.encode('utf-8'),
            'action': 'opensearch',
            'limit': str(limit),
            'namespace': str(namespace),
            'format': 'xml',
        }
        url = '%s?%s' % (self.URL, urlencode(query_params))
        response = yield http_request(url, '', {
            'User-Agent': 'Vumi HTTP Request',
        }, method='GET')
        returnValue(self.parse_xml(response))
开发者ID:mangroveorg,项目名称:vumi,代码行数:27,代码来源:wikipedia.py


示例2: make_request

    def make_request(self, session_type, session_id, reply=None,
                     continue_session=True, expect_msg=True,
                     defer_response=False, **kw):
        url_suffix = "session/%s/%s" % (session_id, session_type)
        method = self.SESSION_HTTP_METHOD.get(session_type, "POST")
        request_data = self.DEFAULT_SESSION_DATA[session_type].copy()
        request_data.update(kw)
        deferred_req = http_request(self.worker_url + url_suffix,
                                    json.dumps(request_data), method=method)
        if not expect_msg:
            msg = None
        else:
            [msg] = yield self.broker.wait_messages("vumi",
                                                    "test_infobip.inbound",
                                                    1)
            self.broker.clear_messages("vumi", "test_infobip.inbound")
            msg = TransportUserMessage(**msg.payload)
            if reply is not None:
                reply_msg = msg.reply(reply, continue_session=continue_session)
                self.broker.publish_message("vumi", "test_infobip.outbound",
                                         reply_msg)

        if defer_response:
            response = deferred_req
        else:
            response = yield deferred_req
        returnValue((msg, response))
开发者ID:BantouTelecom,项目名称:vumi,代码行数:27,代码来源:test_infobip.py


示例3: test_inbound_resume_continue

 def test_inbound_resume_continue(self):
     url = "%s%s?%s" % (
         self.transport_url,
         self.config['web_path'],
         urlencode({
             'ussdSessionId': 123,
             'msisdn': 555,
             'provider': 'web',
             'request': 1,
         })
     )
     d = http_request(url, '', method='GET')
     msg, = yield self.wait_for_dispatched_messages(1)
     payload = msg.payload
     self.assertEqual(payload['transport_name'], self.transport_name)
     self.assertEqual(payload['transport_type'], "ussd")
     self.assertEqual(payload['transport_metadata'],
                      {"session_id": "123"})
     self.assertEqual(payload['session_event'],
                      TransportUserMessage.SESSION_RESUME)
     self.assertEqual(payload['from_addr'], '555')
     self.assertEqual(payload['to_addr'], '')
     self.assertEqual(payload['content'], '1')
     tum = TransportUserMessage(**payload)
     rep = tum.reply("OK")
     self.dispatch(rep)
     response = yield d
     correct_response = '<request>\n\t<headertext>OK</headertext>\n\t' \
             '<options>\n\t\t<option command="1" order="1" ' \
             'callback="http://localhost/foo" display="False" >' \
             '</option>\n\t</options>\n</request>'
     self.assertEqual(response, correct_response)
开发者ID:BantouTelecom,项目名称:vumi,代码行数:32,代码来源:test_vodacom_messaging.py


示例4: test_inbound

 def test_inbound(self):
     url = '%s%s?%s' % (
         self.transport_url,
         self.config['web_path'],
         urlencode([
             ('to_msisdn', 555),
             ('to_msisdn', 556),
             ('from_msisdn', 123),
             ('message', 'hello'),
         ])
     )
     response = yield http_request(url, '', method='GET')
     [msg1, msg2] = self.tx_helper.get_dispatched_inbound()
     self.assertEqual(msg1['transport_name'], self.tx_helper.transport_name)
     self.assertEqual(msg1['to_addr'], "555")
     self.assertEqual(msg2['to_addr'], "556")
     self.assertEqual(msg1['from_addr'], "123")
     self.assertEqual(msg1['content'], "hello")
     self.assertEqual(json.loads(response), [
         {
             'id': msg1['message_id'],
             'message': msg1['content'],
             'from_msisdn': msg1['from_addr'],
             'to_msisdn': msg1['to_addr'],
         },
         {
             'id': msg2['message_id'],
             'message': msg2['content'],
             'from_msisdn': msg2['from_addr'],
             'to_msisdn': msg2['to_addr'],
         },
     ])
开发者ID:AndrewCvekl,项目名称:vumi,代码行数:32,代码来源:test_oldapi.py


示例5: test_inbound_new_continue

 def test_inbound_new_continue(self):
     url = "%s%s?%s" % (
         self.transport_url,
         self.config['web_path'],
         urlencode({
             'ussdSessionId': 123,
             'msisdn': 555,
             'provider': 'web',
             'request': '*120*666#',
         }))
     d = http_request(url, '', method='GET')
     msg, = yield self.tx_helper.wait_for_dispatched_inbound(1)
     self.assertEqual(msg['transport_name'], self.tx_helper.transport_name)
     self.assertEqual(msg['transport_type'], "ussd")
     self.assertEqual(msg['transport_metadata'], {
         "session_id": "123"
     })
     self.assertEqual(msg['session_event'],
         TransportUserMessage.SESSION_NEW)
     self.assertEqual(msg['from_addr'], '555')
     self.assertEqual(msg['to_addr'], '*120*666#')
     self.assertEqual(msg['content'], '*120*666#')
     self.tx_helper.make_dispatch_reply(msg, "OK")
     response = yield d
     correct_response = '<request>\n\t<headertext>OK</headertext>\n\t' \
             '<options>\n\t\t<option command="1" order="1" ' \
             'callback="http://127.0.0.1/foo" display="False" >' \
             '</option>\n\t</options>\n</request>'
     self.assertEqual(response, correct_response)
开发者ID:AndrewCvekl,项目名称:vumi,代码行数:29,代码来源:test_vodacom_messaging.py


示例6: make_request

    def make_request(self, session_type, session_id, reply=None,
                     continue_session=True, expect_msg=True,
                     defer_response=False, **kw):
        url_suffix = "session/%s/%s" % (session_id, session_type)
        method = self.SESSION_HTTP_METHOD.get(session_type, "POST")
        request_data = self.DEFAULT_SESSION_DATA[session_type].copy()
        request_data.update(kw)
        deferred_req = http_request(self.transport_url + url_suffix,
                                    json.dumps(request_data), method=method)
        if not expect_msg:
            msg = None
        else:
            [msg] = yield self.tx_helper.wait_for_dispatched_inbound(1)
            self.tx_helper.clear_all_dispatched()
            if reply is not None:
                yield self.tx_helper.make_dispatch_reply(
                    msg, reply, continue_session=continue_session)

        if defer_response:
            response = deferred_req
            # We need to make sure we wait for the response so we don't leave
            # the reactor dirty if the test runner wins the race with the HTTP
            # client.
            self.add_cleanup(lambda: deferred_req)
        else:
            response = yield deferred_req
        returnValue((msg, response))
开发者ID:AndrewCvekl,项目名称:vumi,代码行数:27,代码来源:test_infobip.py


示例7: test_inbound_resume_close

 def test_inbound_resume_close(self):
     args = "/?ussdSessionId=123&msisdn=555&provider=web&request=1"
     url = "%s%s?%s" % (
         self.transport_url,
         self.config['web_path'],
         urlencode({
             'ussdSessionId': 123,
             'msisdn': 555,
             'provider': 'web',
             'request': 1,
         })
     )
     d = http_request(url, '', method='GET')
     msg, = yield self.wait_for_dispatched_messages(1)
     payload = msg.payload
     self.assertEqual(payload['transport_name'], self.transport_name)
     self.assertEqual(payload['transport_type'], "ussd")
     self.assertEqual(payload['transport_metadata'],
                      {"session_id": "123"})
     self.assertEqual(payload['session_event'],
                      TransportUserMessage.SESSION_RESUME)
     self.assertEqual(payload['from_addr'], '555')
     self.assertEqual(payload['to_addr'], '')
     self.assertEqual(payload['content'], '1')
     tum = TransportUserMessage(**payload)
     rep = tum.reply("OK", False)
     self.dispatch(rep)
     response = yield d
     correct_response = '<request>\n\t<headertext>OK' + \
                         '</headertext>\n</request>'
     self.assertEqual(response, correct_response)
开发者ID:mangroveorg,项目名称:vumi,代码行数:31,代码来源:test_vodacom_messaging.py


示例8: test_receipt_processing

    def test_receipt_processing(self):
        """it should be able to process an incoming XML receipt via HTTP"""

        identifier = '001efc31'
        message_id = '123456'
        # prime redis to match the incoming identifier to an
        # internal message id
        yield self.transport.set_message_id_for_identifier(
            identifier, message_id)

        xml_data = """
        <?xml version="1.0"?>
        <!DOCTYPE receipts>
        <receipts>
          <receipt>
            <msgid>26567958</msgid>
            <reference>%s</reference>
            <msisdn>+27123456789</msisdn>
            <status>D</status>
            <timestamp>20080831T15:59:24</timestamp>
            <billed>NO</billed>
          </receipt>
        </receipts>
        """.strip() % identifier
        yield http_request(
            self.transport.get_transport_url('receipt.xml'), xml_data)
        self.assertEqual([], self.tx_helper.get_dispatched_failures())
        self.assertEqual([], self.tx_helper.get_dispatched_inbound())
        [event] = yield self.tx_helper.wait_for_dispatched_events(1)
        self.assertEqual(event['delivery_status'], 'delivered')
        self.assertEqual(event['message_type'], 'event')
        self.assertEqual(event['event_type'], 'delivery_report')
        self.assertEqual(event['user_message_id'], message_id)
开发者ID:AndrewCvekl,项目名称:vumi,代码行数:33,代码来源:test_opera.py


示例9: handle_outbound_message

 def handle_outbound_message(self, message):
     text = message['content']
     if text is None:
         text = ''
     flags = '0'
     if message['session_event'] == message.SESSION_CLOSE:
         flags = '1'
     session_id = message['transport_metadata']['session_id']
     response = yield http_request(self.integrat_url, hxg.build({
         'Flags': flags,
         'SessionID': session_id,
         'Type': 'USSReply',
         'USSText': text,
         'Password': self.integrat_password,
         'UserID': self.integrat_username,
     }), headers={
         'Content-Type': ['text/xml; charset=utf-8']
     }, agent_class=self.agent_factory)
     error = hxg.parse_response(response)
     if not error:
         yield self.publish_ack(user_message_id=message['message_id'],
                                sent_message_id=message['message_id'])
     else:
         yield self.publish_nack(
             user_message_id=message['message_id'],
             sent_message_id=message['message_id'],
             reason=', '.join([': '.join(ef.items()[0])
                               for ef in error['error_fields']]))
开发者ID:AndrewCvekl,项目名称:vumi,代码行数:28,代码来源:integrat.py


示例10: test_inbound_resume_close

 def test_inbound_resume_close(self):
     url = "%s%s?%s" % (
         self.transport_url,
         self.config['web_path'],
         urlencode({
             'ussdSessionId': 123,
             'msisdn': 555,
             'provider': 'web',
             'request': 1,
         })
     )
     d = http_request(url, '', method='GET')
     msg, = yield self.tx_helper.wait_for_dispatched_inbound(1)
     self.assertEqual(msg['transport_name'], self.tx_helper.transport_name)
     self.assertEqual(msg['transport_type'], "ussd")
     self.assertEqual(msg['transport_metadata'], {"session_id": "123"})
     self.assertEqual(
         msg['session_event'], TransportUserMessage.SESSION_RESUME)
     self.assertEqual(msg['from_addr'], '555')
     self.assertEqual(msg['to_addr'], '')
     self.assertEqual(msg['content'], '1')
     self.tx_helper.make_dispatch_reply(msg, "OK", continue_session=False)
     response = yield d
     correct_response = '<request>\n\t<headertext>OK' + \
                         '</headertext>\n</request>'
     self.assertEqual(response, correct_response)
开发者ID:AndrewCvekl,项目名称:vumi,代码行数:26,代码来源:test_vodacom_messaging.py


示例11: test_good_optional_parameter

 def test_good_optional_parameter(self):
     url = self.mkurl('hello', group='#channel')
     response = yield http_request(url, '', method='GET')
     [msg] = self.tx_helper.get_dispatched_inbound()
     self.assertEqual(msg['group'], '#channel')
     self.assertEqual(json.loads(response),
                      {'message_id': msg['message_id']})
开发者ID:AndrewCvekl,项目名称:vumi,代码行数:7,代码来源:test_api.py


示例12: test_non_json_content

 def test_non_json_content(self):
     response = yield http_request(self.worker_url + "session/1/start",
                                   "not json at all", method="POST")
     correct_response = {
         'responseExitCode': 400,
         'responseMessage': 'Invalid JSON',
         }
     self.assertEqual(json.loads(response), correct_response)
开发者ID:BantouTelecom,项目名称:vumi,代码行数:8,代码来源:test_infobip.py


示例13: _make_call

 def _make_call(self, params):
     params.setdefault("format", "json")
     url = "%s?%s" % (self.URL, urlencode(params))
     headers = {"User-Agent": "Vumi HTTP Request"}
     if self.GZIP:
         headers["Accept-Encoding"] = "gzip"
     response = yield http_request(url, "", headers, method="GET")
     returnValue(json.loads(response))
开发者ID:preillyme,项目名称:vumi-wikipedia,代码行数:8,代码来源:wikipedia.py


示例14: test_inbound_with_failed_auth

 def test_inbound_with_failed_auth(self):
     headers = {
         'Authorization': basic_auth_string("user-1", "bad-pass")
     }
     d = http_request(self.transport_url + "foo", '',
                      headers=headers, method='GET')
     response = yield d
     self.assertEqual(response, 'Unauthorized')
开发者ID:AndrewCvekl,项目名称:vumi,代码行数:8,代码来源:test_httprpc.py


示例15: test_ignored_parameters

 def test_ignored_parameters(self):
     url = self.mkurl('hello', channelID='a', keyword='b', CHANNELID='c',
                      serviceID='d', SERVICEID='e', unsub='f')
     response = yield http_request(url, '', method='GET')
     [msg] = self.tx_helper.get_dispatched_inbound()
     self.assertEqual(msg['content'], "hello")
     self.assertEqual(json.loads(response),
                      {'message_id': msg['message_id']})
开发者ID:AndrewCvekl,项目名称:vumi,代码行数:8,代码来源:test_cellulant_sms.py


示例16: test_incoming_sms_processing

    def test_incoming_sms_processing(self):
        """
        it should be able to process in incoming sms as XML delivered via HTTP
        """

        xml_data = """
        <?xml version="1.0"?>
        <!DOCTYPE bspostevent>
        <bspostevent>
          <field name="MOReference" type = "string">282341913</field>
          <field name="IsReceipt" type = "string">NO</field>
          <field name="RemoteNetwork" type = "string">mtn-za</field>
          <field name="BSDate-tomorrow" type = "string">20100605</field>
          <field name="BSDate-today" type = "string">20100604</field>
          <field name="ReceiveDate" type = "date">
                 2010-06-04 15:51:25 +0000</field>
          <field name="Local" type = "string">*32323</field>
          <field name="ClientID" type = "string">4</field>
          <field name="ChannelID" type = "string">111</field>
          <field name="MessageID" type = "string">373736741</field>
          <field name="ReceiptStatus" type = "string"></field>
          <field name="Prefix" type = "string"></field>
          <field name="ClientName" type = "string">Praekelt</field>
          <field name="MobileDevice" type = "string"></field>
          <field name="BSDate-yesterday" type = "string">20100603</field>
          <field name="Remote" type = "string">+27831234567</field>
          <field name="State" type = "string">5</field>
          <field name="MobileNetwork" type = "string">mtn-za</field>
          <field name="MobileNumber" type = "string">+27831234567</field>
          <field name="Text" type = "string">Hello World</field>
          <field name="ServiceID" type = "string">20222</field>
          <field name="RegType" type = "string">1</field>
          <field name="NewSubscriber" type = "string">NO</field>
          <field name="Subscriber" type = "string">+27831234567</field>
          <field name="Parsed" type = "string"></field>
          <field name="ServiceName" type = "string">Prktl Vumi</field>
          <field name="BSDate-thisweek" type = "string">20100531</field>
          <field name="ServiceEndDate" type = "string">
                 2010-06-30 07:47:00 +0200</field>
          <field name="Now" type = "date">2010-06-04 15:51:27 +0000</field>
        </bspostevent>
        """.strip()

        resp = yield http_request(
            self.transport.get_transport_url('receive.xml'), xml_data)

        self.assertEqual([], self.tx_helper.get_dispatched_failures())
        self.assertEqual([], self.tx_helper.get_dispatched_events())
        [msg] = self.tx_helper.get_dispatched_inbound()
        self.assertEqual(msg['message_id'], '373736741')
        self.assertEqual(msg['to_addr'], '32323')
        self.assertEqual(msg['from_addr'], '+27831234567')
        self.assertEqual(msg['content'], 'Hello World')
        self.assertEqual(msg['transport_metadata'], {
            'provider': 'mtn-za'
        })

        self.assertEqual(resp, xml_data)
开发者ID:AndrewCvekl,项目名称:vumi,代码行数:58,代码来源:test_opera.py


示例17: test_http_request_to_localhost

 def test_http_request_to_localhost(self):
     """
     Make a request over the network (localhost) to check that we're getting
     a real agent by default.
     """
     url = yield self.make_real_webserver()
     self.set_render(lambda r: "Yay")
     data = yield http_request(url, '')
     self.assertEqual(data, "Yay")
开发者ID:AndrewCvekl,项目名称:vumi,代码行数:9,代码来源:test_utils.py


示例18: test_status_for_inactive_session

 def test_status_for_inactive_session(self):
     response = yield http_request(self.worker_url + "session/1/status", "",
                                   method="GET")
     correct_response = {
         'responseExitCode': 200,
         'responseMessage': '',
         'sessionActive': False,
         }
     self.assertEqual(json.loads(response), correct_response)
开发者ID:BantouTelecom,项目名称:vumi,代码行数:9,代码来源:test_infobip.py


示例19: test_inbound

 def test_inbound(self):
     d = http_request(self.transport_url + "foo", '', method='GET')
     [msg] = yield self.tx_helper.wait_for_dispatched_inbound(1)
     rep = yield self.tx_helper.make_dispatch_reply(msg, "OK")
     response = yield d
     self.assertEqual(response, 'OK')
     [ack] = yield self.tx_helper.wait_for_dispatched_events(1)
     self.assertEqual(ack['user_message_id'], rep['message_id'])
     self.assertEqual(ack['sent_message_id'], rep['message_id'])
开发者ID:AndrewCvekl,项目名称:vumi,代码行数:9,代码来源:test_httprpc.py


示例20: test_disallowed_default_parameters

 def test_disallowed_default_parameters(self):
     url = self.mkurl_raw(content='hello', from_addr='123')
     response = yield http_request(url, '', method='GET')
     [msg] = self.tx_helper.get_dispatched_inbound()
     self.assertEqual(msg['transport_name'], self.tx_helper.transport_name)
     self.assertEqual(msg['to_addr'], "555")
     self.assertEqual(msg['from_addr'], "123")
     self.assertEqual(msg['content'], "hello")
     self.assertEqual(json.loads(response),
                      {'message_id': msg['message_id']})
开发者ID:AndrewCvekl,项目名称:vumi,代码行数:10,代码来源:test_api.py



注:本文中的vumi.utils.http_request函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.http_request_full函数代码示例发布时间:2022-05-26
下一篇:
Python pdu_utils.seq_no函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap