起因是有个部门分享的 data 是 power BI 数据源 API,我想把这些数据用 python 读取到 pandas 里面,昨天花了很久研究 M query, 不会转换双引号:(, 拿不到 token,刚刚试了下 ChatGPT 给的 code,一次成功.
太厉害了, 以后不用去 stack overflow 了
我: can you convert power bi m code to python?
ChatGPT: Yes, it is possible to convert Power BI M code to Python. However, the conversion process may not be straightforward and will depend on the specific M code that you are trying to convert. Power BI M code is a proprietary language used in the Power BI platform, while Python is a general-purpose programming language that is widely used in data analysis and scientific computing.
If you have specific M code that you would like to convert to Python, I would recommend that you provide the code and I can try to assist you with the conversion. It would also be helpful to know the reason why you want to convert the M code to Python and what you plan to do with the resulting Python code.
我:
let body1 ="{
""username"": " & username &",
""password"": "& password &"
}",
getToken =
Web.Contents(server & tokenAddress, [Content=Text.ToBinary(body1)]),
token1 = "Bearer " & Text.FromBinary(getToken),
ChatGPT: This Power BI M code is defining several variables and making a web request to get a token. The body1 variable is defining the body of the request as a string containing the username and password values. The getToken variable is making a web request to the server & tokenAddress URL with the body1 content. Finally, the token1 variable is constructing a string by concatenating the Bearer string with the response from the getToken web request.
In Python, you can use the requests library to make web requests and parse the response. Here is an example of how the above Power BI M code could be converted to Python:
Copy code
import requests
username = "your_username"
password = "your_password"
server = "
http://your_server.com"
tokenAddress = "/api/get_token"
body1 = {
"username": username,
"password": password
}
getToken =
requests.post(server + tokenAddress, json=body1)
token1 = "Bearer " + getToken.text
Note that this is just an example and may not work exactly as shown if the actual Power BI M code is different from what you provided. You may need to adjust the code depending on the details of your specific use case.
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://www.v2ex.com/t/900780
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.