数据分析思维

python requests库面试笔试题

2020-02-07  本文已影响0人  python测试开发

A. 提供一个清晰简洁的框架来处理HTTP请求。

B. 抽象HTTP协议的复杂部分。

C. Python中发出HTTP请求的事实上的标准。

D. 它是在Python中建立HTTP连接的唯一可用选项。

A. 5xx Server Error

B. 2xx Success

C. 3xx Redirection

D. 1xx Error

E. 4xx Client Error

A. requests.post('https://httpbin.org/post', data={'key':'value'})

B. requests.put('https://httpbin.org/put', data={'key':'value'})

C. requests.delete('https://httpbin.org/delete')

D. requests.tail('https://httpbin.org/tail')

import requests
from requests.exceptions import HTTPError
url = 'https://httpbin.org/'
try:
    response = requests.get(url)
    # If the response was successful, no Exception will be raised
    response.raise_for_status()
except HTTPError as http_err:
    print(f'HTTP error occurred: {http_err}')  
except Exception as err:
    print(f'Other error occurred: {err}')  
else:
    print('Success!')

A. Other error occured

B.Success!

C.HTTP error occurred: 404 Client Error: NOT FOUND for url: https://httpbin.org/

参考资料

A. response.content returns the response content as a string object.

B.response.text returns the response content as a string object.

C.response.text returns the response content as a bytes object.

D.response.json() returns the response content as a json object.

E.response.json returns the response content as a json object.

F.response.content returns the response content as a bytes object.

demo.png

A. requests.get('https://httpbin.org/get', auth=customClassForAuthentication('self_generated_token'))

B.requests.get('https://api.github.com/user', auth=('username', getpass()))

C. requests.get('https://api.github.com/user')

D.requests.get('https://api.github.com/user', auth=HTTPBasicAuth('username', getpass()))

A. Max Retries

B.Timeouts

C. Logging

D.Session Objects

上一篇 下一篇

猜你喜欢

热点阅读