获取请求 python 作为字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32875241/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 12:24:55  来源:igfitidea点击:

Get request python as a string

pythongetrequest

提问by Taimoor Khan

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?

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

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

thanks

谢谢

采纳答案by kakajan

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

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

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

If you want it as string, use

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

req.text