纵有疾风起
人生不言弃

python requests库面试笔试题

  • 1 为什么requests库很重要?

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

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

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

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

  • 2 服务器响应客户端请求发出HTTP状态代码。找出错误项:

A. 5xx Server Error

B. 2xx Success

C. 3xx Redirection

D. 1xx Error

E. 4xx Client Error

  • 3 以下哪些HTTP请求正确?

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’)

  • 4 以下代码的执行结果是?
import requestsfrom requests.exceptions import HTTPErrorurl = '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.

python requests库面试笔试题插图
demo.png
  • 6 以下哪些认证的代码是正确的?

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()))

  • 7 以下哪些和性能无关?

A. Max Retries

B.Timeouts

C. Logging

D.Session Objects

文章转载于:https://www.jianshu.com/p/374dca87802b

原著是一个有趣的人,若有侵权,请通知删除

未经允许不得转载:起风网 » python requests库面试笔试题
分享到: 生成海报

评论 抢沙发

评论前必须登录!

立即登录