获取请求 python 作为字符串 [英] Get request python as a string

查看:37
本文介绍了获取请求 python 作为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 python 中发送一个 get 请求并将其作为字符串返回.我想最终使用该字符串作为稍后的内容.另外默认情况下python是否以json格式返回它?

I wanted to send a get request in python and return it as a string. I wanna eventually use that string as something later on. Also by default does python return it in json format?

req = requests.get(server, auth=('user',"pass"))

谢谢

推荐答案

使用 python请求.检查链接,有示例如何从响应中获取 json.

Use python requests. Check the link, there are examples how you get json from response.

req = requests.get(server, auth=('user',"pass"))
req.json()

如果你想要它作为字符串,使用

If you want it as string, use

req.text

这篇关于获取请求 python 作为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆