9 examples of 'python requests get' in Python

Every line of 'python requests get' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
64def get(url, params=None, **kwargs):
65 r"""Sends a GET request.
66
67 :param url: URL for the new :class:`Request` object.
68 :param params: (optional) Dictionary, list of tuples or bytes to send
69 in the query string for the :class:`Request`.
70 :param \*\*kwargs: Optional arguments that ``request`` takes.
71 :return: :class:`Response <Response>` object
72 :rtype: requests.Response
73 """
74
75 kwargs.setdefault('allow_redirects', True)
76 return request('get', url, params=params, **kwargs)
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

3def get(url, retries=10):
4 #TODO: backoff
5 r = requests.get(url)
6 sleep = .1
7 for _ in range(retries):
8 if r.status_code == 200:
9 return r
10 sleep *= 2
11 print "retrying in {0}".format(sleep)
12 time.sleep(sleep)
13 r = requests.get(url)
14 raise Exception("GET failed.\nstatus: {0}\nurl: {1}".format(r.status_code, url))
492def get(self, url, **kwargs):
493 """Sends a GET request. Returns :class:`Response` object.
494
495 :param url: URL for the new :class:`Request` object.
496 :param \*\*kwargs: Optional arguments that ``request`` takes.
497 :rtype: requests.Response
498 """
499
500 kwargs.setdefault('allow_redirects', True)
501 return self.request('GET', url, **kwargs)
10async def get(url):
11 """请求页面
12 """
13 headers = {
14 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
15 'Host': 'www.funi.com'
16 }
17
18 try:
19 """conn = aiohttp.TCPConnector(verify_ssl=False) connector=conn"""
20 async with aiohttp.ClientSession(headers=headers) as session:
21 async with session.get(url, proxy=proxyServer) as response:
22 return await response.text("utf-8")
23 except TimeoutError as te:
24 print('超时', te)
29def get(url, cookie = None, auth = None, token = None, retries = 5, timeout = 30):
30 headers = {
31 "Content-type": "application/json",
32 "Accept": "application/json",
33 "User-Agent": "Apache Kibble",
34 }
35 if auth:
36 xcreds = auth.encode(encoding='ascii', errors='replace')
37 bauth = base64.encodebytes(xcreds).decode('ascii', errors='replace').replace("\n", '')
38 headers["Authorization"] = "Basic %s" % bauth
39 if token:
40 headers["Authorization"] = "token %s" % token
41 if cookie:
42 headers["Cookie"] = cookie
43 rv = requests.get(url, headers = headers, timeout = (CONNECT_TIMEOUT, timeout))
44 # Some services may be rate limited. We'll try sleeping it off in 60 second
45 # intervals for a max of five minutes, then give up.
46 if rv.status_code == 429:
47 if retries > 0:
48 time.sleep(60)
49 retries -= 1
50 return get(url, cookie = cookie, auth = auth, token = token, retries = retries, timeout = timeout)
51 if rv.status_code < 400:
52 return rv.json()
53 raise requests.exceptions.ConnectionError("Could not fetch JSON, server responded with status code %u" % rv.status_code, response = rv)
31def _get_request(url):
32 try:
33 resp = urlopen(url)
34 return resp.getcode(), resp.read(), resp.info()
35 except IOError as e:
36 return e.getcode(), e.read(), e.info()
209def get(self, url, **kwargs):
210 """Sends a GET request. Returns :class:`Response` object.
211
212 :param url: URL for the new :class:`Request` object.
213 :param **kwargs: Optional arguments that ``request`` takes.
214 """
215
216 kwargs.setdefault('allow_redirects', True)
217 return self.request('get', url, **kwargs)
3def do_get(url, access_token):
4
5 bearer_headers = {'Content-Type': 'application/json',
6 'Accept': 'application/json',
7 'Authorization': 'Bearer {0}'.format(access_token)}
8
9 response = requests.get(url, params=None, headers=bearer_headers, stream=True)
10
11 return response
93def _get(self, url):
94 try:
95 page = self.session.get(url)
96 if page.status_code == 200:
97 page.encoding = 'utf-8'
98 return page
99 else:
100 raise HTTPError('GET {0}\n{1}'.format(url, page))
101 except requests.exceptions.RequestException as e:
102 raise NetworkError(repr(e))

Related snippets