当前位置: 首页>>代码示例>>Python>>正文


Python HTTP.get方法代码示例

本文整理汇总了Python中Naked.toolshed.network.HTTP.get方法的典型用法代码示例。如果您正苦于以下问题:Python HTTP.get方法的具体用法?Python HTTP.get怎么用?Python HTTP.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Naked.toolshed.network.HTTP的用法示例。


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

示例1: test_http_get_response_check_200

# 需要导入模块: from Naked.toolshed.network import HTTP [as 别名]
# 或者: from Naked.toolshed.network.HTTP import get [as 别名]
 def test_http_get_response_check_200(self):
     """Confirm that the response object contains 200 status code"""
     http = HTTP('http://httpbin.org/status/200')
     http.get()
     self.assertEqual(http.res.status_code, 200) # test the response object attribute
     response = http.response()
     self.assertEqual(response.status_code, 200) # test the returned object from the response() method
开发者ID:chrisidefix,项目名称:naked,代码行数:9,代码来源:test_NETWORK.py

示例2: test_http_get_response_check_404

# 需要导入模块: from Naked.toolshed.network import HTTP [as 别名]
# 或者: from Naked.toolshed.network.HTTP import get [as 别名]
 def test_http_get_response_check_404(self):
     """Confirm that the response object contains a 404 status code when authentication required"""
     http = HTTP('http://httpbin.org/status/404')
     http.get()
     self.assertEqual(http.res.status_code, 404)
     response = http.response()
     self.assertEqual(response.status_code, 404)
开发者ID:chrisidefix,项目名称:naked,代码行数:9,代码来源:test_NETWORK.py

示例3: test_http_get_response_check_301

# 需要导入模块: from Naked.toolshed.network import HTTP [as 别名]
# 或者: from Naked.toolshed.network.HTTP import get [as 别名]
 def test_http_get_response_check_301(self):
     """Confirm that the reponse object contains 301 status code when do not follow redirects"""
     http = HTTP('http://httpbin.org/status/301')
     http.get(False) # do not follow redirects
     self.assertEqual(http.res.status_code, 301)
     response = http.response()
     self.assertEqual(response.status_code, 301)
开发者ID:chrisidefix,项目名称:naked,代码行数:9,代码来源:test_NETWORK.py

示例4: test_http_get_response_obj_present

# 需要导入模块: from Naked.toolshed.network import HTTP [as 别名]
# 或者: from Naked.toolshed.network.HTTP import get [as 别名]
 def test_http_get_response_obj_present(self):
     """Confirm that response object is set after GET request with site that exists"""
     http = HTTP('http://google.com')
     http.get()
     self.assertTrue(http.res)             # the response object
     self.assertTrue(http.res.content)     # the content of the response
     self.assertTrue(http.res.status_code) # the status code
开发者ID:chrisidefix,项目名称:naked,代码行数:9,代码来源:test_NETWORK.py

示例5: get_response

# 需要导入模块: from Naked.toolshed.network import HTTP [as 别名]
# 或者: from Naked.toolshed.network.HTTP import get [as 别名]
    def get_response(self):
        try:
            the_url = prepare_url(self.url)
            http = HTTP(the_url)
            http.get()
            resp = http.response()

            # confirm that a response was returned, abort if not
            if resp == None and the_url.startswith('https://'):
                stderr("Unable to connect to the requested URL. This can happen if the secure HTTP protocol is not supported at the requested URL.")
                sys.exit(1)
            elif resp == None:
                stderr("Unable to connect to the requested URL. Please confirm your URL and try again.")
                sys.exit(1)

            if len(resp.history) > 0:
                count = len(resp.history)
                for i in range(count):
                    print(str(resp.history[i].status_code) + " : " + str(resp.history[i].url))
            print(str(http.res.status_code) + " : " + http.res.url)
            exit_success()
        except ConnectionError:
            error_string = "Unable to connect to the URL, " + self.url
            stderr(error_string, 1)
        except Exception as e:
            raise e
开发者ID:chrissimpkins,项目名称:status,代码行数:28,代码来源:http_request.py

示例6: test_http_get_ssl

# 需要导入模块: from Naked.toolshed.network import HTTP [as 别名]
# 或者: from Naked.toolshed.network.HTTP import get [as 别名]
    def test_http_get_ssl(self):
        """Test HTTP GET request content data with secure HTTP"""
        http = HTTP("https://raw.github.com/chrissimpkins/six-four/master/LICENSE")
        http_text = http.get()

        if state.py2:
            self.http_string = unicode(self.http_string)
        self.assertEqual(http_text.strip(), self.http_string.strip())
开发者ID:chrisidefix,项目名称:naked,代码行数:10,代码来源:test_NETWORK.py

示例7: test_http_get_type

# 需要导入模块: from Naked.toolshed.network import HTTP [as 别名]
# 或者: from Naked.toolshed.network.HTTP import get [as 别名]
    def test_http_get_type(self):
        """Test the HTTP GET request return value type"""
        http = HTTP("https://raw.github.com/chrissimpkins/six-four/master/LICENSE")
        http_text = http.get()

        if state.py2:
            self.assertEqual(type(u"test string"), type(http_text))
        else:
            self.assertEqual(type(str("test string")), type(http_text))
开发者ID:chrisidefix,项目名称:naked,代码行数:11,代码来源:test_NETWORK.py

示例8: test_http_get_response_obj_nonexistentsite

# 需要导入模块: from Naked.toolshed.network import HTTP [as 别名]
# 或者: from Naked.toolshed.network.HTTP import get [as 别名]
 def test_http_get_response_obj_nonexistentsite(self):
     """Test the response object after GET request for a non-existent site"""
     http = HTTP('http://bigtimebogussite.io')
     self.assertEqual(False, http.get())
     self.assertEqual(None, http.res)
     with self.assertRaises(AttributeError):
         http.res.content
     with self.assertRaises(AttributeError):
         http.res.status_code
开发者ID:chrisidefix,项目名称:naked,代码行数:11,代码来源:test_NETWORK.py

示例9: run

# 需要导入模块: from Naked.toolshed.network import HTTP [as 别名]
# 或者: from Naked.toolshed.network.HTTP import get [as 别名]
    def run(self):
        from Naked.toolshed.network import HTTP
        http = HTTP(self.url) # use the python.org url for the classifier list

        print('•naked• Pulling the classifier list from python.org...')

        res = http.get() # get the list
        test_list = res.split('\n') # split on newlines

        if self.needle == "": # user did not enter a search string, print the entire list
            print("•naked• You did not provide a search string.  Here is the entire list:")
            print(' ')
            for item in test_list:
                print(item)
        else: # user entered a search string, find it
            lower_needle = self.needle.lower()
            print("•naked• Performing a case insensitive search for '" + self.needle + "'")
            print(' ')
            filtered_list = [ x for x in test_list if lower_needle in x.lower() ] #case insensitive match for the search string
            for item in filtered_list:
                print(item)

        exit_success() # exit with zero status code
开发者ID:INAP-LABS,项目名称:noc-orchestrator,代码行数:25,代码来源:classifier.py

示例10: test_http_get_follow_redirects

# 需要导入模块: from Naked.toolshed.network import HTTP [as 别名]
# 或者: from Naked.toolshed.network.HTTP import get [as 别名]
 def test_http_get_follow_redirects(self):
     """Confirm that the GET request follows redirects and returns 200 status code by default"""
     http = HTTP("http://httpbin.org/status/301")
     http_text = http.get()
     self.assertEqual(200, http.res.status_code)
开发者ID:chrisidefix,项目名称:naked,代码行数:7,代码来源:test_NETWORK.py

示例11: test_http_get_response_method_return_value_missingsite

# 需要导入模块: from Naked.toolshed.network import HTTP [as 别名]
# 或者: from Naked.toolshed.network.HTTP import get [as 别名]
 def test_http_get_response_method_return_value_missingsite(self):
     """Test the return type from response() method after GET request when non-existent site is requested"""
     http = HTTP('http://www.abogussitename.com')
     http.get()
     self.assertEqual(None, http.response())
开发者ID:chrisidefix,项目名称:naked,代码行数:7,代码来源:test_NETWORK.py

示例12: test_http_get_status_ssl_redirect

# 需要导入模块: from Naked.toolshed.network import HTTP [as 别名]
# 或者: from Naked.toolshed.network.HTTP import get [as 别名]
 def test_http_get_status_ssl_redirect(self):
     """Confirm that GET request for a https domain returns appropriate 301 status code when redirects"""
     http = HTTP('https://httpbin.org/status/301')
     http.get(False) # do not allow redirects in order to capture this code
     self.assertEqual(http.res.status_code, 301)
开发者ID:chrisidefix,项目名称:naked,代码行数:7,代码来源:test_NETWORK.py

示例13: test_http_get_follow_redirects_false_on_nofollow_arg

# 需要导入模块: from Naked.toolshed.network import HTTP [as 别名]
# 或者: from Naked.toolshed.network.HTTP import get [as 别名]
 def test_http_get_follow_redirects_false_on_nofollow_arg(self):
     """Confirm that GET request does not follow redirect and returns non-200 status code when requested"""
     http = HTTP("http://httpbin.org/status/301")
     http_text = http.get(follow_redirects=False)
     self.assertEqual(301, http.res.status_code)
开发者ID:chrisidefix,项目名称:naked,代码行数:7,代码来源:test_NETWORK.py

示例14: test_http_get_status_ssl

# 需要导入模块: from Naked.toolshed.network import HTTP [as 别名]
# 或者: from Naked.toolshed.network.HTTP import get [as 别名]
 def test_http_get_status_ssl(self):
     """Confirm that GET request for a https domain returns appropriate status code"""
     http = HTTP('https://httpbin.org/status/200')
     http.get()
     self.assertEqual(http.res.status_code, 200)
开发者ID:chrisidefix,项目名称:naked,代码行数:7,代码来源:test_NETWORK.py

示例15: test_http_get_follow_redirects_false_content

# 需要导入模块: from Naked.toolshed.network import HTTP [as 别名]
# 或者: from Naked.toolshed.network.HTTP import get [as 别名]
 def test_http_get_follow_redirects_false_content(self):
     """Test the contents of the returned data from the GET request when site returns non-200 status code"""
     http = HTTP("http://httpbin.org/status/301")
     http_text = http.get(follow_redirects=False)
     self.assertEqual("", http_text)
开发者ID:chrisidefix,项目名称:naked,代码行数:7,代码来源:test_NETWORK.py


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