Merge pull request #1 from LCTT/master

update from LCTT
This commit is contained in:
aREversez 2022-03-14 08:54:20 +08:00 committed by GitHub
commit b2486a51e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 639 additions and 468 deletions

View File

@ -3,39 +3,35 @@
[#]: author: "Moshe Zadka https://opensource.com/users/moshez"
[#]: collector: "lujun9972"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: url: "https://linux.cn/article-14353-1.html"
如何使用 httpx一个 Python web 客户端
httpx一个 Python Web 客户端
======
Python 的 httpx 包是一个用于 HTTP 交互的一个优秀且灵活的模块。
![Digital creative of a browser on the internet][1]
Python 的 `httpx` 包是一个复杂的 web 客户端。当你安装它后,你就可以用它来从网站上获取数据。像往常一样,安装它的最简单方法是使用 `pip` 工具:
> Python 的 httpx 包是一个用于 HTTP 交互的一个优秀且灵活的模块。
![](https://img.linux.net.cn/data/attachment/album/202203/13/102042hmtif0i7g3fg0ir0.jpg)
Python 的 `httpx` 包是一个复杂的 Web 客户端。当你安装它后,你就可以用它来从网站上获取数据。像往常一样,安装它的最简单方法是使用 `pip` 工具:
```
`$ python -m pip install httpx --user`
$ python -m pip install httpx --user
```
要使用它,把它导入到 Python 脚本中,然后使用 `.get` 函数从一个 web 地址获取数据:
```
import httpx
result = httpx.get("<https://httpbin.org/get?hello=world>")
result = httpx.get("https://httpbin.org/get?hello=world")
result.json()["args"]
```
下面是这个简单脚本的输出:
```
` {'hello': 'world'}`
{'hello': 'world'}
```
### HTTP 响应
@ -44,97 +40,71 @@ result.json()["args"]
试试这个代码:
```
result = httpx.get("<https://httpbin.org/status/404>")
result = httpx.get("https://httpbin.org/status/404")
result
```
结果是:
```
` <Response [404 NOT FOUND]>`
<Response [404 NOT FOUND]>
```
可以明确地返回一个响应。添加这个异常处理:
```
try:
result.raise_for_status()
except Exception as exc:
print("woops", exc)
```
下面是结果:
```
woops Client error '404 NOT FOUND' for url '<https://httpbin.org/status/404>'
For more information check: <https://httpstatuses.com/404>
woops Client error '404 NOT FOUND' for url 'https://httpbin.org/status/404'
For more information check: https://httpstatuses.com/404
```
### 自定义客户端
除了最简单的脚本之外,使用一个自定义的客户端是值得的。除了不错的性能改进,比如连接池,这是一个配置客户端的好地方。
除了最简单的脚本之外,使用一个自定义的客户端是有意义的。除了不错的性能改进,比如连接池,这是一个配置客户端的好地方。
例如, 你可以设置一个自定义的基本 URL
```
client = httpx.Client(base_url="<https://httpbin.org>")
client = httpx.Client(base_url="https://httpbin.org")
result = client.get("/get?source=custom-client")
result.json()["args"]
```
输出示例:
```
` {'source': 'custom-client'}`
{'source': 'custom-client'}
```
这对一个典型的场景很有用,你用客户端与一个特定的服务器对话。例如,使用 `base_url``auth`,你可以为认证的客户端建立一个漂亮的抽象:
这对用客户端与一个特定的服务器对话的典型场景很有用。例如,使用 `base_url``auth`,你可以为认证的客户端建立一个漂亮的抽象:
```
client = httpx.Client(
base_url="<https://httpbin.org>",
base_url="https://httpbin.org",
auth=("good_person", "secret_password"),
)
result = client.get("/basic-auth/good_person/secret_password")
result.json()
```
输出:
```
` {'authenticated': True, 'user': 'good_person'}`
{'authenticated': True, 'user': 'good_person'}
```
你可以用它来做一件更好的事情,就是在顶层的 “main” 函数中构建客户端,然后把它传递给其他函数。这可以让其他函数使用客户端,并让它们与连接到本地 WSGI 应用的客户端进行单元测试。
你可以用它来做一件更棒的事情,就是在顶层的 “主” 函数中构建客户端,然后把它传递给其他函数。这可以让其他函数使用客户端,并让它们与连接到本地 WSGI 应用的客户端进行单元测试。
```
def get_user_name(client):
result = client.get("/basic-auth/good_person/secret_password")
return result.json()["user"]
@ -145,16 +115,14 @@ get_user_name(client)
def application(environ, start_response):
start_response('200 OK', [('Content-Type', 'application/json')])
return [b'{"user": "pretty_good_person"}']
fake_client = httpx.Client(app=application, base_url="<https://fake-server>")
fake_client = httpx.Client(app=application, base_url="https://fake-server")
get_user_name(fake_client)
```
输出:
```
` 'pretty_good_person'`
'pretty_good_person'
```
### 尝试 httpx
@ -168,7 +136,7 @@ via: https://opensource.com/article/22/3/python-httpx
作者:[Moshe Zadka][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -3,71 +3,67 @@
[#]: author: "Marco Carmona https://itsfoss.com/author/marco/"
[#]: collector: "lujun9972"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: url: "https://linux.cn/article-14355-1.html"
基于 Ubuntu 和 Debian 的发行版上通过命令行改 变Linux 系统语言Locales
在 Ubuntu 上通过命令行改变 Linux 系统语言
======
_**简介:这是一个快速教程,展示了在 Ubuntu 和其他 Linux 发行版上从命令行改变语言的步骤。**_
![](https://img.linux.net.cn/data/attachment/album/202203/13/223937s17qtqz931grud89.jpg)
我已经有一段时间没有在 It's FOSS 上写东西了。事实上,我一直在为 Its FOSS 的西班牙语版本写文章。如果你没有访问过它并且/或你是一个讲西班牙语的人,请访问 [It's FOSS en Español][1] 并查看所有西班牙语的 Linux 内容
> 这是一个快速教程,展示了在 Ubuntu 和其他 Linux 发行版上从命令行改变语言的步骤
你可能想知道我为什么要和你分享这个事实。 这是因为这篇文章以这个新页面为例
事实上,我一直在写西班牙语的文章。如果你没有访问过它并且/或你是一个讲西班牙语的人,请访问 [It's FOSS en Español][1] 并查看所有西班牙语的 Linux 内容
在进行[你喜欢的 Linux 发行版][2]的干净安装时,系统会要求你选择一种主语言。尽管这并不频繁,但有些人后来还是考虑把这个语言改成新的,比如说我
你可能想知道我为什么要和你分享这件事,这是因为这篇文章以这个新页面为例
你看,我必须同时用西班牙语(为 It's FOSS en Español和英语为 It's FOSS进行截屏。这就成了一个问题因为我只有一台电脑而更换用户对我来说不是一个快速的解决方案。
在新安装 [你喜欢的 Linux 发行版][2] 时,系统会要求你选择一种主语言。有些人,比如说我,后来会考虑把这个语言改成新的,尽管这并不频繁。
你看,我必须同时用西班牙语和英语进行截屏。这就成了一个问题,因为我只有一台电脑,而更换用户对我来说不是一个快速的解决方案。
这就是为什么我想和你分享这个快速技巧,我将告诉你如何在终端中用两行简单的文字改变你的主系统语言。
让我们开始吧!
让我们开始吧
### 从终端改变 Linux 系统语言
假设你想把你的主语言从英语改为西班牙语。
确认你将哪种语言设置为默认语言(主语言)。为此,让我们使用 locale 命令。
确认你将哪种语言设置为默认语言(主语言)。为此,让我们使用 `locale` 命令。
```
locale
locale
```
你应该看到像这样的东西
你应该看到像这样的东西
```
[email protected]:~$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
team@itsfoss:~$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
```
在这里你可以看到主语言是英语。现在要改变它,请按以下方式使用 dpkg 命令:
在这里你可以看到主语言是英语。现在要改变它,请按以下方式使用 `dpkg` 命令:
```
sudo dpkg-reconfigure locales
sudo dpkg-reconfigure locales
```
当你运行之前的命令,你应该在终端看到下面的页面
当你运行之前的命令,你应该在终端看到下面的页面
![sudo dpkg reconfigure locales][3]
@ -86,17 +82,15 @@ _**简介:这是一个快速教程,展示了在 Ubuntu 和其他 Linux 发
完成后,你应该在你的终端看到这样的信息:
```
Generating locales (this might take a while)...
en_US.UTF-8... done
es_MX.UTF-8... done
Generation complete.
Generating locales (this might take a while)...
en_US.UTF-8... done
es_MX.UTF-8... done
Generation complete.
```
_**这就完成了**_!现在你能够直接从终端改变你的默认语言,次数不限。
这就完成了!现在你能够直接从终端改变你的默认语言,次数不限。
如果你对这个话题有任何疑问,请在评论区告诉我们。_***好样的!***_
如果你对这个话题有任何疑问,请在评论区告诉我们。
--------------------------------------------------------------------------------
@ -105,7 +99,7 @@ via: https://itsfoss.com/change-locales-linux/
作者:[Marco Carmona][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -0,0 +1,120 @@
[#]: subject: "KDE Plasma 5.24 Review. A Crafted Desktop to Dominate the Linux World"
[#]: via: "https://www.debugpoint.com/2022/03/kde-plasma-5-24-review/"
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
[#]: collector: "lujun9972"
[#]: translator: "wxy"
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: url: "https://linux.cn/article-14352-1.html"
KDE Plasma 5.24:精心制作的主宰 Linux 世界的桌面
======
> 是时候对前段时间发布的 KDE Plasma 5.24 桌面进行一次简单的回顾和点评了。
KDE 团队用他们完美的 KDE Plasma 5.24 再次做到了。一个在效率、新功能、性能、稳定性和一切方面都非常完美的版本为所有用户带来了一个优秀的桌面环境。
KDE Plasma 5.24 是 Plasma 的第 26 个版本也是长期支持LTS版本它将为 Kubuntu 22.04 LTS Jammy Jellyfish 添彩。这意味着你、我和全世界成千上万的用户将使用这个版本两年或更长的时间。你可以想象这个版本是多么重要。
不多说了,让我们去快速点评一下 KDE Plasma 5.24。
![KDE Plasma 5.24 桌面](https://img.linux.net.cn/data/attachment/album/202203/12/202450k5x811c83661w3ix.jpg)
### KDE Plasma 5.24 点评
#### 安装
我在 Fedora 上使用 [KDE Plasma 5.24][2] 已经有一段时间了。这次是直接从 [KDE Plasma 5.23][3] 升级而来。在升级过程中,一切都很顺利。所有的用户配置的设置都保持不变,只有默认的壁纸在升级后被改变了。所以,数据或启动加载出现问题是几乎不可能的。
我在一个实体系统中安装了 KDE Plasma 5.24 和 KDE Neon 用户版以进一步测试。在一个 4GB 内存的英特尔 i3 系统中,安装很顺利,大约花了 8 分钟。
这个测试系统上还有另一个操作系统,所以安装程序完美地检测到了所有的操作系统并正确地更新了 GRUB。
#### 新功能、外观和可用性
Plasma 5.24 看起来很震撼。第一次启动后呈现出一个干净的桌面,具有经典的外观和极其漂亮的壁纸。默认的 Breeze Light 主题加上新的边框和装饰,对每个用户来说几乎是完美的。如果你很好奇,想给你的 Plasma 换一个不同的外观,那么所有的设置,如重点颜色之类的都在那里。你不需要通过什么秘籍或命令行来改变外观。
新设计的概览屏幕给你一种 GNOME 的氛围,但在 KDE 环境下,当你设置好它时,它就会变得非常棒。
![KDE Plasma 概览效果][4]
在我的测试中我尝试了蓝牙、Wi-Fi 和打印(安装 HPLIP 后)—— 都很顺利。没有磕磕绊绊也不需要命令行一切都开箱即用。KDE Plasma 的通知区应该可以让你访问所有必要的选项,你很少需要访问系统设置对话框。
![蓝牙设置很简单][5]
电池使用情况尚可,我认为在我的测试硬件上,自 Plasma 5.23 以来电池使用情况略有改善。我把测试机保持在待机状态Plasma 很轻松就唤醒了,没有任何问题。我知道有些 Linux 发行版在睡眠后无法唤醒,导致你得在 TTY 里重启或启动 X 会话。
#### 稳定性和性能
不管你是一个 Plasma 的新用户还是长期用户Plasma 5.24 都会让你有宾至如归的感觉;一切都准备好了,没有错误,等待你的行动和工作流程。
在我的测试期间中,我没有遇到任何错误。因此,我 [快速翻阅][7] 了 KDE 官方论坛,看看在发布后的一个月内报告了多少种问题以及有多少问题。不多,实际上只有寥寥两位数。而且报告的问题大多与高端显示器和网络有关,我觉得这与特定的专业硬件有关。
但总的来说,如今它是一个构建良好且经过测试的桌面。
在过去的几个版本中KDE Plasma 在任何硬件上的性能都是完美的。而这个版本也证明了这一点。
在空闲阶段KDE Plasma 5.24 消耗了 614MB 的内存CPU 使用率为 2%。
![KDE Plasma 5.24 在闲置模式下的性能][8]
我通过 Firefox 运行了五个标签,并播放了 Youtube。同时用一个文件管理器、文本编辑器、图片浏览器、系统设置和“发现”包管理器的实例来测试重载下的性能。这个用例使用了 1.29GB 的内存,而 CPU 平均在 6% 到 7%。
显然Firefox 消耗了大部分的系统资源。
![KDE Plasma 5.24 在重度工作负载模式下][9]
我必须说,这是一个了不起的性能指标。
所以,有了这个版本,就有了一个完美的 Plasma 桌面。
#### 如何获得 KDE Plasma 5.24
KDE Plasma 5.24 现在可以在 KDE Neon 用户版,和通过 Backports PPA 在 Fedora 35 和 Kubuntu 21.10 上使用。如果你想重新安装,你可以从 [这里][10] 下载它。
如果你使用的是 Fedora 35 和 Kubuntu 21.10,请按照这些指南来获得这个版本。
- [在 Fedora 上升级 Plasma][11]
- [如何在 Kubuntu 21.10 中安装 KDE Plasma 5.24][12]
### 结束语
我为我们的网站点评测试过许多 Linux 发行版和桌面环境。没有哪个能在各个方面接近 KDE Plasma。我知道 GNOME 设计得很好而且还有其他的小亮点但是当你需要一个省心的系统而且几乎所有的自定义选项都开箱即用时KDE Plasma 几十年来一直是赢家。
有的时候,为了让系统能在短时间内运行起来而无需太多折腾,我只有安装 KDE Plasma 才行。因为到最后,它肯定能工作,所有的选项都可以供你使用。
我认为运行 KDE Plasma 的 Kubuntu/Fedora 和 Linux Mint 是当今世界上最好的几个发行版,毫无疑问。
作为对本篇 KDE Plasma 5.24 点评的总结我必须得承认KDE Plasma 5.24 LTS 是该团队的一个本垒打。我们很高兴 KDE 的存在,并将在未来的日子里占据主导地位。
加油!
--------------------------------------------------------------------------------
via: https://www.debugpoint.com/2022/03/kde-plasma-5-24-review/
作者:[Arindam][a]
选题:[lujun9972][b]
译者:[wxy](https://github.com/wxy)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.debugpoint.com/author/admin1/
[b]: https://github.com/lujun9972
[1]: https://www.debugpoint.com/wp-content/uploads/2022/02/KDE-Plasma-5.4-Desktop-1024x576.jpg
[2]: https://www.debugpoint.com/2022/01/kde-plasma-5-24/
[3]: https://www.debugpoint.com/2021/08/kde-plasma-5-23/
[4]: https://www.debugpoint.com/wp-content/uploads/2021/11/KDE-Plasma-Overview-Effect-1-1024x434.jpg
[5]: https://www.debugpoint.com/wp-content/uploads/2022/03/Easy-Bluetooth-Setup.jpg
[6]: https://www.debugpoint.com/2021/05/archcraft-os-review/
[7]: https://forum.kde.org/search.php?keywords=5.24&terms=all&author=&tags=&sv=0&sc=1&sf=all&sr=posts&sk=t&sd=d&st=30&ch=300&t=0&submit=Search
[8]: https://www.debugpoint.com/wp-content/uploads/2022/03/KDE-Plasma-5.24-Performance-in-Idle-Mode.jpg
[9]: https://www.debugpoint.com/wp-content/uploads/2022/03/KDE-Plasma-5.24-in-Heavy-Workload-Mode.jpg
[10]: https://neon.kde.org/download
[11]: https://www.debugpoint.com/2022/02/upgrade-kde-plasma-5-24/
[12]: https://www.debugpoint.com/wp-admin/post.php?post=9018&action=edit
[13]: https://t.me/debugpoint
[14]: https://twitter.com/DebugPoint
[15]: https://www.youtube.com/c/debugpoint?sub_confirmation=1
[16]: https://facebook.com/DebugPoint

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (amagicbowboy)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -1,233 +0,0 @@
[#]: subject: "How to use undocumented web APIs"
[#]: via: "https://jvns.ca/blog/2022/03/10/how-to-use-undocumented-web-apis/"
[#]: author: "Julia Evans https://jvns.ca/"
[#]: collector: "lujun9972"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
How to use undocumented web APIs
======
Hello! A couple of days I wrote about [tiny personal programs][1], and I mentioned that it can be fun to use “secret” undocumented APIs where you need to copy your cookies out of the browser to get access to them.
A couple of people asked how to do this, so I wanted to explain how because its pretty straightforward. Well also talk a tiny bit about what can go wrong, ethical issues, and how this applies to your undocumented APIs.
As an example, lets use Google Hangouts. Im picking this not because its the most useful example (I think theres an official API which would be much more practical to use), but because many sites where this is actually useful are smaller sites that are more vulnerable to abuse. So were just going to use Google Hangouts because Im 100% sure that the Google Hangouts backend is designed to be resilient to this kind of poking around.
Lets get started!
### step 1: look in developer tools for a promising JSON response
I start out by going to <https://hangouts.google.com>, opening the network tab in Firefox developer tools and looking for JSON responses. You can use Chrome developer tools too.
Heres what that looks like
![][2]
The request is a good candidate if it says “json” in the “Type” column”
I had to look around for a while until I found something interesting, but eventually I found a “people” endpoint that seems to return information about my contacts. Sounds fun, lets take a look at that.
### step 2: copy as cURL
Next, I right click on the request Im interested in, and click “Copy” -&gt; “Copy as cURL”.
Then I paste the `curl` command in my terminal and run it. Heres what happens.
```
$ curl 'https://people-pa.clients6.google.com/v2/people/?key=REDACTED' -X POST ........ (a bunch of headers removed)
Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: <FILE>" to save to a file.
```
You might be thinking thats weird, whats this “binary output can mess up your terminal” error? Thats because by default, browsers send an `Accept-Encoding: gzip, deflate` header to the server, to get compressed output.
We could decompress it by piping the output to `gunzip`, but I find it simpler to just not send that header. So lets remove some irrelevant headers.
### step 3: remove irrelevant headers
Heres the full `curl` command line that I got from the browser. Theres a lot here! I start out by splitting up the request with backslashes (`\`) so that each header is on a different line to make it easier to work with:
```
curl 'https://people-pa.clients6.google.com/v2/people/?key=REDACTED' \
-X POST \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:96.0) Gecko/20100101 Firefox/96.0' \
-H 'Accept: */*' \
-H 'Accept-Language: en' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'X-HTTP-Method-Override: GET' \
-H 'Authorization: SAPISIDHASH REDACTED' \
-H 'Cookie: REDACTED'
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'X-Goog-AuthUser: 0' \
-H 'Origin: https://hangouts.google.com' \
-H 'Connection: keep-alive' \
-H 'Referer: https://hangouts.google.com/' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: same-site' \
-H 'Sec-GPC: 1' \
-H 'DNT: 1' \
-H 'Pragma: no-cache' \
-H 'Cache-Control: no-cache' \
-H 'TE: trailers' \
--data-raw 'personId=101777723309&personId=1175339043204&personId=1115266537043&personId=116731406166&extensionSet.extensionNames=HANGOUTS_ADDITIONAL_DATA&extensionSet.extensionNames=HANGOUTS_OFF_NETWORK_GAIA_GET&extensionSet.extensionNames=HANGOUTS_PHONE_DATA&includedProfileStates=ADMIN_BLOCKED&includedProfileStates=DELETED&includedProfileStates=PRIVATE_PROFILE&mergedPersonSourceOptions.includeAffinity=CHAT_AUTOCOMPLETE&coreIdParams.useRealtimeNotificationExpandedAcls=true&requestMask.includeField.paths=person.email&requestMask.includeField.paths=person.gender&requestMask.includeField.paths=person.in_app_reachability&requestMask.includeField.paths=person.metadata&requestMask.includeField.paths=person.name&requestMask.includeField.paths=person.phone&requestMask.includeField.paths=person.photo&requestMask.includeField.paths=person.read_only_profile_info&requestMask.includeField.paths=person.organization&requestMask.includeField.paths=person.location&requestMask.includeField.paths=person.cover_photo&requestMask.includeContainer=PROFILE&requestMask.includeContainer=DOMAIN_PROFILE&requestMask.includeContainer=CONTACT&key=REDACTED'
```
This can seem like an overwhelming amount of stuff at first, but you dont need to think about what any of it means at this stage. You just need to delete irrelevant lines.
I usually just figure out which headers I can delete with trial and error I keep removing headers until the request starts failing. In general you probably dont need `Accept*`, `Referer`, `Sec-*`, `DNT`, `User-Agent`, and caching headers though.
In this example, I was able to cut the request down to this:
```
curl 'https://people-pa.clients6.google.com/v2/people/?key=REDACTED' \
-X POST \
-H 'Authorization: SAPISIDHASH REDACTED' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Origin: https://hangouts.google.com' \
-H 'Cookie: REDACTED'\
--data-raw 'personId=101777723309&personId=1175339043204&personId=1115266537043&personId=116731406166&extensionSet.extensionNames=HANGOUTS_ADDITIONAL_DATA&extensionSet.extensionNames=HANGOUTS_OFF_NETWORK_GAIA_GET&extensionSet.extensionNames=HANGOUTS_PHONE_DATA&includedProfileStates=ADMIN_BLOCKED&includedProfileStates=DELETED&includedProfileStates=PRIVATE_PROFILE&mergedPersonSourceOptions.includeAffinity=CHAT_AUTOCOMPLETE&coreIdParams.useRealtimeNotificationExpandedAcls=true&requestMask.includeField.paths=person.email&requestMask.includeField.paths=person.gender&requestMask.includeField.paths=person.in_app_reachability&requestMask.includeField.paths=person.metadata&requestMask.includeField.paths=person.name&requestMask.includeField.paths=person.phone&requestMask.includeField.paths=person.photo&requestMask.includeField.paths=person.read_only_profile_info&requestMask.includeField.paths=person.organization&requestMask.includeField.paths=person.location&requestMask.includeField.paths=person.cover_photo&requestMask.includeContainer=PROFILE&requestMask.includeContainer=DOMAIN_PROFILE&requestMask.includeContainer=CONTACT&key=REDACTED'
```
So I just need 4 headers: `Authorization`, `Content-Type`, `Origin`, and `Cookie`. Thats a lot more manageable.
### step 4: translate it into Python
Now that we know what headers we need, we can translate our `curl` command into a Python program! This part is also a pretty mechanical process, the goal is just to send exactly the same data with Python as we were with curl.
Heres what that looks like. This is exactly the same as the previous `curl` command, but using Pythons `requests`. I also broke up the very long request body string into an array of tuples to make it easier to work with programmmatically.
```
import requests
import urllib
data = [
('personId','101777723'), # I redacted these IDs a bit too
('personId','117533904'),
('personId','111526653'),
('personId','116731406'),
('extensionSet.extensionNames','HANGOUTS_ADDITIONAL_DATA'),
('extensionSet.extensionNames','HANGOUTS_OFF_NETWORK_GAIA_GET'),
('extensionSet.extensionNames','HANGOUTS_PHONE_DATA'),
('includedProfileStates','ADMIN_BLOCKED'),
('includedProfileStates','DELETED'),
('includedProfileStates','PRIVATE_PROFILE'),
('mergedPersonSourceOptions.includeAffinity','CHAT_AUTOCOMPLETE'),
('coreIdParams.useRealtimeNotificationExpandedAcls','true'),
('requestMask.includeField.paths','person.email'),
('requestMask.includeField.paths','person.gender'),
('requestMask.includeField.paths','person.in_app_reachability'),
('requestMask.includeField.paths','person.metadata'),
('requestMask.includeField.paths','person.name'),
('requestMask.includeField.paths','person.phone'),
('requestMask.includeField.paths','person.photo'),
('requestMask.includeField.paths','person.read_only_profile_info'),
('requestMask.includeField.paths','person.organization'),
('requestMask.includeField.paths','person.location'),
('requestMask.includeField.paths','person.cover_photo'),
('requestMask.includeContainer','PROFILE'),
('requestMask.includeContainer','DOMAIN_PROFILE'),
('requestMask.includeContainer','CONTACT'),
('key','REDACTED')
]
response = requests.post('https://people-pa.clients6.google.com/v2/people/?key=REDACTED',
headers={
'X-HTTP-Method-Override': 'GET',
'Authorization': 'SAPISIDHASH REDACTED',
'Content-Type': 'application/x-www-form-urlencoded',
'Origin': 'https://hangouts.google.com',
'Cookie': 'REDACTED',
},
data=urllib.parse.urlencode(data),
)
print(response.text)
```
I ran this program and it works it prints out a bunch of JSON! Hooray!
Youll notice that I replaced a bunch of things with `REDACTED`, thats because if I included those values you could access the Google Hangouts API for my account which would be no good.
### and were done!
Now I can modify the Python program to do whatever I want, like passing different parameters or parsing the output.
Im not going to do anything interesting with it because Im not actually interested in using this API at all, I just wanted to show what the process looks like.
But we get back a bunch of JSON that you could definitely do something with.
### curlconverter looks great
Someone commented that you can translate curl to Python (and a bunch of other languages!) automatically with <https://curlconverter.com/> which looks amazing Ive always done it manually. I tried it out on this example and it seems to work great.
### figuring out how the API works is nontrivial
I dont want to undersell how difficult it can be to figure out how an unknown API works its not obvious! I have no idea what a lot of the parameters to this Google Hangouts API do!
But a lot of the time there are some parameters that seem pretty straightforward, like `requestMask.includeField.paths=person.email` probably means “include each persons email address”. So I try to focus on the parameters I _do_ understand more than the ones I _dont_ understand.
### this always works (in theory)
Some of you might be wondering can you always do this?
The answer is sort of yes browsers arent magic! All the information browsers send to your backend is just HTTP requests. So if I copy all of the HTTP headers that my browser is sending, I think theres literally no way for the backend to tell that the request _isnt_ sent by my browser and is actually being sent by a random Python program.
Of course, we removed a bunch of the headers the browser sent so theoretically the backend _could_ tell, but usually they wont check.
There are some caveats though for example a lot of Google services have backends that communicate with the frontend in a totally inscrutable (to me) way, so even though in theory you could mimic what theyre doing, in practice it might be almost impossible. And bigger APIs that encounter more abuse will have more protections.
Now that weve seen how to use undocumented APIs like this, lets talk about some things that can go wrong.
### problem 1: expiring session cookies
One big problem here is that Im using my Google session cookie for authentication, so this script will stop working whenever my browser session expires.
That means that this approach wouldnt work for a long running program (Id want to use a real API), but if I just need to quickly grab a little bit of data as a 1-time thing, it can work great!
### problem 2: abuse
If Im using a small website, theres a chance that my little Python script could take down their service because its doing way more requests than theyre able to handle. So when Im doing this I try to be respectful and not make too many requests too quickly.
This is especially important because a lot of sites which dont have official APIs are smaller sites with less resources.
In this example obviously this isnt a problem I think I made 20 requests total to the Google Hangouts backend while writing this blog post, which they can definitely handle.
Also if youre using your account credentials to access the API in a excessive way and you cause problems, you might (very reasonably) get your account suspended.
I also stick to downloading data thats either mine or thats intended to be publicly accessible Im not searching for vulnerabilities.
### remember that anyone can use your undocumented APIs
I think the most important thing to know about this isnt actually how to use _other peoples_ undocumented APIs. Its fun to do, but it has a lot of limitations and I dont actually do it that often.
Its much more important to understand that anyone can do this to _your_ backend API! Everyone has developer tools and the network tab, and its pretty easy to see which parameters youre passing to the backend and to change them.
So if anyone can just change some parameters to get another users information, thats no good. I think most developers building publicly availble APIs know this, but Im mentioning it because everyone needs to learn it for the first time at some point :)
--------------------------------------------------------------------------------
via: https://jvns.ca/blog/2022/03/10/how-to-use-undocumented-web-apis/
作者:[Julia Evans][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://jvns.ca/
[b]: https://github.com/lujun9972
[1]: https://jvns.ca/blog/2022/03/08/tiny-programs/
[2]: https://jvns.ca/images/network-tab.png

View File

@ -1,130 +0,0 @@
[#]: subject: "KDE Plasma 5.24 Review. A Crafted Desktop to Dominate the Linux World"
[#]: via: "https://www.debugpoint.com/2022/03/kde-plasma-5-24-review/"
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
[#]: collector: "lujun9972"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
KDE Plasma 5.24 Review. A Crafted Desktop to Dominate the Linux World
======
ITS TIME FOR A QUICK RECAP AND REVIEW OF THE KDE PLASMA 5.24 DESKTOP,
RELEASED A WHILE BACK.
The KDE team did it again with their perfect KDE Plasma 5.24 release. A fantastic release in terms of efficiency, new features, performance, stability, and everything in between makes an excellent desktop environment for all types of users.
KDE Plasma 5.24 is the 26th edition of Plasma and Long Term Support (LTS) release to grace the Kubuntu 22.04 LTS Jammy Jellyfish. That means you, me and thousands of users worldwide will be using this version for two or more years. You can fathom how important this release is.
Without much rambling, lets go for a quick review of KDE Plasma 5.24.
![KDE Plasma 5.24 Desktop][1]
### KDE Plasma 5.24 Review
#### Installation
I have been using [KDE Plasma 5.24][2] in Fedora for quite some time. So, that installation was a direct upgrade from [KDE Plasma 5.23][3]. On the upgrade process front, everything went smooth. All the user-configured settings remained intact, and only the default wallpaper is changed after the upgrade. So surprises or any loss to data or boot loader.
I have installed KDE Plasma 5.24 with KDE Neon user edition in a physical system to test further. The installation went fine with around 8 minutes in an Intel i3 system with 4GB RAM.
The test system had another operating system, so the installer perfectly detected all the operating systems and updated the grub correctly.
#### New Features, Look and feel and Usability
Plasma 5.24 looks stunning. The first boot presents a clean desktop with a classic look and incredible wallpaper. The default Breeze Light theme with new borders and decorations are almost perfect for every user. And if you are curious and want a different look for your Plasma, then all the settings such as accent colour and stuff are all right there. You do not need to hack or reach for the command line for changing the look.
The newly designed overview screen gives you a GNOME vibe, but its awesome in the KDE environment when you set it up.
![KDE Plasma Overview Effect -1][4]
During my test, I tried Bluetooth, WiFi, and printing (after installing HPLIP) all went smooth. No hiccups or command line is required. Everything worked out of the box. The notification area of KDE Plasma should give you access to all the necessary options. You seldom need to visit the System Settings dialogue.
![Easy Bluetooth Setup][5]
The battery usage is fair, and I think a slight improvement since the Plasma 5.23 in my test hardware. I kept the test machine to reach standby, and Plasma woke up nicely without any problem. I know some Linux distributions fail to wake up after sleep and lead you to go to TTY and reboot or start the X session again.
#### Stability and Performance
If you are a new or long-term Plasma user, Plasma 5.24 would feel like a home; everything is ready, bug-free and waiting for your actions and workflow.
[][6]
SEE ALSO:   Archcraft OS - Minimal Arch Linux with Openbox WM
I have not encountered any bugs during my test window. So, I did a [quick scan][7] on the official KDE Forum on how many issues and types of problems have been reported in one month since the release. Its not much, actually in two digits. And the reported issues are mostly related to high-end displays and networks that I feel are related to specific specialized hardware.
But in general, it is a well built and well-tested desktop out there today.
KDE Plasma performance was always perfect in any hardware for the past couple of releases. And this release also proves the same.
During the idle phase, KDE Plasma 5.24 consumes 614 MB of RAM with 2% CPU usage.
![KDE Plasma 5.24 Performance in Idle Mode][8]
I ran it through Firefox with five tabs and played Youtube. Also, with one instance of File Manager, text editor, image viewer, system settings, and Discover to test the heavy workload performance. This use case uses 1.29 GB of RAM, and the CPU is at an average of 6% to 7%.
Firefox, obviously consuming most of the system resources.
![KDE Plasma 5.24 in Heavy Workload Mode][9]
A remarkable performance metric, I must say.
So, there you have it, a perfect Plasma desktop with this release.
#### How to get KDE Plasma 5.24
KDE Plasma 5.24 is now available with KDE Neon user edition, Fedora 35 and Kubuntu 21.10 via backports PPA. You can download it from [here][10] if you want a fresh install.
If you are using Fedora 35 and Kubuntu 21.10, follow these guides to get this version.
[Upgrade Plasma for Fedora][11]
[How to Get KDE Plasma 5.24 in Kubuntu 21.10 Impish Indri][12]
### Closing Notes
I review and test many Linux distributions and desktop environments for our portal. Nothing comes close to KDE Plasma in every aspect. I know GNOME is well designed and has other tricks, but still, when you need a fast system with almost all customization options out of the box, KDE Plasma has been the winner for decades.
There were times when I had to install KDE Plasma to get a system up and running in no time without worrying much. Because in the end, it just works, and all the options are ready for you to use.
I think KDE Plasma with Kubuntu/Fedora and Linux Mint is the two best distribution in the world today hands down.
To wrap up the KDE Plasma 5.24 review, I am compelled to say that KDE Plasma 5.24 LTS is a home run from the team. And we are glad that KDE exists and is about to dominate in days to come.
Cheers.
* * *
We bring the latest tech, software news and stuff that matters. Stay in touch via [Telegram][13], [Twitter][14], [YouTube][15], and [Facebook][16] and never miss an update!
##### Also Read
--------------------------------------------------------------------------------
via: https://www.debugpoint.com/2022/03/kde-plasma-5-24-review/
作者:[Arindam][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.debugpoint.com/author/admin1/
[b]: https://github.com/lujun9972
[1]: https://www.debugpoint.com/wp-content/uploads/2022/02/KDE-Plasma-5.4-Desktop-1024x576.jpg
[2]: https://www.debugpoint.com/2022/01/kde-plasma-5-24/
[3]: https://www.debugpoint.com/2021/08/kde-plasma-5-23/
[4]: https://www.debugpoint.com/wp-content/uploads/2021/11/KDE-Plasma-Overview-Effect-1-1024x434.jpg
[5]: https://www.debugpoint.com/wp-content/uploads/2022/03/Easy-Bluetooth-Setup.jpg
[6]: https://www.debugpoint.com/2021/05/archcraft-os-review/
[7]: https://forum.kde.org/search.php?keywords=5.24&terms=all&author=&tags=&sv=0&sc=1&sf=all&sr=posts&sk=t&sd=d&st=30&ch=300&t=0&submit=Search
[8]: https://www.debugpoint.com/wp-content/uploads/2022/03/KDE-Plasma-5.24-Performance-in-Idle-Mode.jpg
[9]: https://www.debugpoint.com/wp-content/uploads/2022/03/KDE-Plasma-5.24-in-Heavy-Workload-Mode.jpg
[10]: https://neon.kde.org/download
[11]: https://www.debugpoint.com/2022/02/upgrade-kde-plasma-5-24/
[12]: https://www.debugpoint.com/wp-admin/post.php?post=9018&action=edit
[13]: https://t.me/debugpoint
[14]: https://twitter.com/DebugPoint
[15]: https://www.youtube.com/c/debugpoint?sub_confirmation=1
[16]: https://facebook.com/DebugPoint

View File

@ -0,0 +1,219 @@
[#]: subject: "Best 5 Alternatives to Microsoft Office [Compared]"
[#]: via: "https://www.debugpoint.com/2022/03/best-alternatives-microsoft-office-2022/"
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
[#]: collector: "lujun9972"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Best 5 Alternatives to Microsoft Office [Compared]
======
HERE WE GIVE YOU THE FIVE BEST ALTERNATIVES TO MICROSOFT OFFICE. WE
COMPARE THEM BASED ON FEATURES, ARE EASY TO USE AND PROVIDE YOU GUIDE TO
CHOOSE THE ONE YOU NEED.
I think we all agree that Microsoft Office is one of the best software developed by Mircosoft. It has a presence almost everywhere in the entire world in nearly every business. It is a fine piece of software that evolved over a couple of past decades.
And obviously, it doesnt have a Linux native installer and comes with a significant price. If you are a business owner or a personal user, the current Microsoft Office 365 subscription pricing is a little higher. And not everyone can afford that price bucket for a longer time.
Then what are the alternatives? You can try other options that relatively get the job done for most users or businesses.
This article gives you the five best alternatives to Microsoft Office.
### Best Alternatives to Microsoft Office
### LibreOffice
![LibreOffice][1]
The first alternative we highlight here is [LibreOffice][2]. The Document Foundation develops and manages the entire LibreOffice free and open-source office suite, available for Linux, macOS and Windows.
It comes with a spreadsheet ([Calc][3]), word processor (Writer), presentation (Impress), drawing (Draw) and a database program (Base).
This project is actively developed, and compatibility with Microsoft Office documents is improved in every release iteration. If appropriately used, LibreOffice can effectively do all the work that a Mircosoft office program does. A massive set of documentation and communities can help you adopt LibreOffice in no time.
If you are a small or a large corporation, you dont need to pay for the software itself. But paid deployment and support is also available at minimal cost if you require them for your critical work.
However, LibreOffice does not come with an Outlook-like email program. This might be one of the minor drawbacks, but you can access emails from web browsers today for all email service providers.
* [Home page][2]
* [For Business][4]
* [Download for general-purpose personal use][5]
* [Help and Documentation][6]
* [Official support forum][7]
* * *
### Google Docs
![Google Docs][8]
The search engine giant Google provides a complete web-based Office suite (aka [Google Docs][9]) with its own Docs (document processor), Sheets (spreadsheet program) and Slides (presentation) for free users.
You can access and create documents in your Google Drive account by default for free and access them from anywhere in the world. The office components provide well-designed web-based toolbars, advanced options, spell check, Voice to Text feature (only in Chrome), encryption and cloud access. Google also offers mobile apps for iOS and Android to access your documents and edit them on the go.
One of the best features of Google Docs is templates. With the power of pre-built templates, you can start professional-grade documents in time. The collaboration option gives you more control when sharing and deploying documents with a Google account-based authentication and authorization mechanism for a wider audience.
If you need more from Google Docs, you may opt for Google Workspace with a very minimal price compared to costly Microsoft Office. The Google Workspace is a complete and integrated solution that gives you Google Forms to collect data and integrate into your docs and Sheets, website builder Google Sites, Google Calendar and more storage options to keep your document.
* [Home page][9]
* [Documentation][10]
### OnlyOffice
![OnlyOffice][11]
[OnlyOffice][12] (styled as ONLYOFFICE) is a free and open-source complete Office productivity suite that contains text editor, spreadsheet program, presentation tool for you and your office work. It supports advanced features such as real-time collaboration with proper tracking changes for your shared documents, fillable forms and many such features.
This powerful office suite looks better with its Office 365 type ribbons which helps to adopt this program quickly. OnlyOffice has better Microsoft Office compatibility with .docx .xlsx and .pptx file formats which are easy for you and your organization to share documents.
[][13]
SEE ALSO:   10 Best Apps to Improve Your GNOME Experience [Part 1]
Its worth mentioning that OnlyOffice provides an Enterprise office suite,, aka “ONLYOFFICE Workspace, ” a paid product with additional features and instant support. This enterprise suite is perfect for those with a tight budget on office products but needs near compatibility with Office 365.
The ONLYOFFICE Workspace comes with an Email client, CRM product, Project Management tool and an integrated calendar. Although everything works well, you face some issues with spell checking, print preview, page size and some bugs. But you should not worry as the team is receptive, and you can report issues in GitHub and get help.
* [Home page][12]
* [Download][14]
* [Documentation and help][15]
### Softmaker Free Office
![FreeOffice][16]
The [FreeOffice][17] is another option if you are looking for Microsoft Office alternatives. This office suite was developed by SoftMaker and is arguably one of the choices that you may have. The FreeOffice brings TextMaker (like Word), PlanMaker (like Excel), Presentations and a comparison utility. The user interfaces as two options. The modern Ribbon option makes it a desirable product due to its popularity. It also has a traditional Legacy user interface with a menu and toolbar with a considerable fanbase.
The SoftMaker FreeOffice provides a specific user interface and features in touch-based devices. The Microsoft Office document format compatibility is well established to get the most done.
However, you may have little trouble working with Open Document Format files, whose support is limited.
This is a closed source product.
* [Home page][17]
* [Download][18]
* [Documentation and help][19]
### WPS Office
![WPS Office][20]
Remember Kingston Office? Well, its now renamed and repackaged as WPS Office, which is the acronym for ord, **P**resentation and **S**preadsheets. Today, the WPS Office is one of the oldest office suites with more than three decades of development and releases. It is a fully-featured office suite available for all platforms and mobile devices.
Some of the unique features of WPS Office are its real-time collaboration in its core programs which helps you work in a team in a shared document. The office suite comes with 100,000+ templates which allows you to create professional-grade documents and presentations.
The WPS Office comes with the standard edition, free to download and use but limited in features.
If you need additional features such as PDF editing, Cloud support, collaborations and enterprise support, then you can opt for the WPS Premium of WPS Business option with a price.
Its important to mention that this is a closed source program and may contain Ads. Also its developed by a Chinese company.
* [Home page][21]
* [Documentation][22]
* [Download][23]
### Comparison
Heres a quick comparison of the above free Microsoft office alternatives based on features and other details.
Product | Price | Source Type | Pros | Cons
---|---|---|---|---
LibreOffice | Free | Open source | Free and cross platform
Multi language support
Complete support of ODF files
Best compatibility support of Microsoft Office
Very active deleopment | No email and project management suite
The database program depends on Java
Google Docs | Free | Close source | Free and cross platform
Well documented support
Access documents via cloud anywhere
Complete Mobile device support | Requires internet connection
Little slow due to web based tool
No native desktop executable available
OnlyOffice | Free (basic product) | Open source | The user interface almost similar to Microsoft Office
Better support and compatibility with Microsoft Office files
Cloud integration, and plugin support
Cross platform | May face problems with some basic features.
Cloud integrations are not compatible with EU due to GDPR
The web app version is slow
FreeOffice | Free (basic product) | Close source | Free and lightweight compared to LibreOffice.
Touchscreen support
Good Microsoft Office compatibility
Cross platform | Free version only have document, spreadsheet and presentation.
Additional prodcuts needs purchase
Open Document Format support is limited
Not open source product
WPS Office | Free | Close source | Good Microsoft office compatibility
Cross platform product
Tabbed interface
Multi language support | Not open source product
Developed by a Chinese company
May contain ads
### Our Recommendation
Leaving aside all the pros and cons, if you cannot choose which of the Office suite is best for you, I would recommend going ahead with LibreOffice always. Because LibreOffice and TDF has a good vision, active development and worldwide community support. LibreOffice has a considerable knowledge base about tips tutorials on the helpful web. And you can easily automate tasks with Basic or Python Macro.
### Closing Notes
I hope this guide helps you choose the best alternatives for Microsoft Office for your personal or business usage. Genuinely speaking, none of the above office products come close in comparison to Microsoft Office in true sense. Not everyone or every business is able to pay hefty subscription fee every month for Microsoft Office. For those, I believe some of these options can be a good starting point.
_Some image credits: Respective product owner_
* * *
We bring the latest tech, software news and stuff that matters. Stay in touch via [Telegram][24], [Twitter][25], [YouTube][26], and [Facebook][27] and never miss an update!
##### Also Read
--------------------------------------------------------------------------------
via: https://www.debugpoint.com/2022/03/best-alternatives-microsoft-office-2022/
作者:[Arindam][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.debugpoint.com/author/admin1/
[b]: https://github.com/lujun9972
[1]: https://www.debugpoint.com/wp-content/uploads/2022/03/LibreOffice-1024x535.jpg
[2]: https://www.libreoffice.org/discover/libreoffice/
[3]: https://www.debugpoint.com/category/libreoffice/libreoffice-calc/
[4]: https://www.libreoffice.org/download/libreoffice-in-business/
[5]: https://www.libreoffice.org/download/download/
[6]: https://help.libreoffice.org/latest/en-US/text/shared/05/new_help.html
[7]: https://ask.libreoffice.org/
[8]: https://www.debugpoint.com/wp-content/uploads/2022/03/Google-Docs.jpg
[9]: https://www.google.com/docs/about/
[10]: https://support.google.com/docs/?hl=en#topic=1382883
[11]: https://www.debugpoint.com/wp-content/uploads/2022/03/OnlyOffice.jpg
[12]: https://www.onlyoffice.com/
[13]: https://www.debugpoint.com/2021/12/best-gnome-apps-part-1/
[14]: https://www.onlyoffice.com/desktop.aspx
[15]: https://forum.onlyoffice.com/
[16]: https://www.debugpoint.com/wp-content/uploads/2022/03/FreeOffice.jpg
[17]: https://www.freeoffice.com/en/
[18]: https://www.freeoffice.com/en/download/applications
[19]: https://forum.softmaker.com/
[20]: https://www.debugpoint.com/wp-content/uploads/2022/03/WPS-Office-1024x499.jpg
[21]: https://www.wps.com/
[22]: https://www.wps.com/academy/
[23]: https://www.wps.com/download/
[24]: https://t.me/debugpoint
[25]: https://twitter.com/DebugPoint
[26]: https://www.youtube.com/c/debugpoint?sub_confirmation=1
[27]: https://facebook.com/DebugPoint

View File

@ -0,0 +1,233 @@
[#]: subject: "How to use undocumented web APIs"
[#]: via: "https://jvns.ca/blog/2022/03/10/how-to-use-undocumented-web-apis/"
[#]: author: "Julia Evans https://jvns.ca/"
[#]: collector: "lujun9972"
[#]: translator: "lxbwolf"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
如何调用没有文档说明的 web API
======
大家好!几天前我写了篇[个人 demo 小程序][1],里面提到了调用没有文档说明的“私有” API 很有意思,你需要从你的浏览器中把 cookies 复制出来才能访问。
有些读者问如何实现,因此我打算详细描述下,其实过程很简单。我们还会涉及一点点在调用没有文档说明的 API 时,可能会遇到的麻烦。
我们用谷歌论坛举例。我之所以选择它,不是因为这个例子最有用(我认为官方的 API 更有实践意义),而是因为在这个场景中更有用的网站很多是小网站,而小网站的 API 一旦被滥用,受到的伤害会更大。因此我们使用谷歌论坛,因为我 100% 肯定谷歌论坛对于这种试探请求可以很快恢复。
我们现在开始!
### 第一步:打开开发者工具,找一个 JSON 响应
我浏览了<https://hangouts.google.com>,在 Firefox 的开发者工具中打开网络标签,找到一个 JSON 响应。你也可以使用 Chrome 的开发者工具。
打开之后界面如下图
![][2]
找到其中一条 “Type” 列显示为 ”json“ 的请求。
为了找一条感兴趣的请求,我找了好一会儿,突然我找到一条 ”people“ 的 endpoint看起来是返回我们的联系人信息。听起来很有意思我们来看一下。
### 第二步:复制为 cURL
下一步,我在感兴趣的请求上右键,点击 ”复制“ -> ”复制为 cURL“。
然后我把 `curl` 命令粘贴到终端并运行。下面是运行结果:
```
$ curl 'https://people-pa.clients6.google.com/v2/people/?key=REDACTED' -X POST ........ (a bunch of headers removed)
Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: <FILE>" to save to a file.
```
你可能会想 —— 很奇怪,”二进制的输出在你的终端上无法正常显示“ 是什么错误?原因是,浏览器默认情况下发给服务器的请求头中有 `Accept-Encoding: gzip, deflate` 参数,会把输出结果进行压缩。
我们可以通过管道把输出传递给 `gunzip` 来解压,但是我们发现不带这个参数进行请求会更简单。因此我们去掉一些不相关的请求头。
### 第三步:去掉不相关的请求头
下面是我从浏览器获得的完整 `curl` 命令。有很多行!我用反斜杠(`\`)把请求分开,这样每个请求头占一行,看起来更清晰。
```
curl 'https://people-pa.clients6.google.com/v2/people/?key=REDACTED' \
-X POST \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:96.0) Gecko/20100101 Firefox/96.0' \
-H 'Accept: */*' \
-H 'Accept-Language: en' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'X-HTTP-Method-Override: GET' \
-H 'Authorization: SAPISIDHASH REDACTED' \
-H 'Cookie: REDACTED'
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'X-Goog-AuthUser: 0' \
-H 'Origin: https://hangouts.google.com' \
-H 'Connection: keep-alive' \
-H 'Referer: https://hangouts.google.com/' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: same-site' \
-H 'Sec-GPC: 1' \
-H 'DNT: 1' \
-H 'Pragma: no-cache' \
-H 'Cache-Control: no-cache' \
-H 'TE: trailers' \
--data-raw 'personId=101777723309&personId=1175339043204&personId=1115266537043&personId=116731406166&extensionSet.extensionNames=HANGOUTS_ADDITIONAL_DATA&extensionSet.extensionNames=HANGOUTS_OFF_NETWORK_GAIA_GET&extensionSet.extensionNames=HANGOUTS_PHONE_DATA&includedProfileStates=ADMIN_BLOCKED&includedProfileStates=DELETED&includedProfileStates=PRIVATE_PROFILE&mergedPersonSourceOptions.includeAffinity=CHAT_AUTOCOMPLETE&coreIdParams.useRealtimeNotificationExpandedAcls=true&requestMask.includeField.paths=person.email&requestMask.includeField.paths=person.gender&requestMask.includeField.paths=person.in_app_reachability&requestMask.includeField.paths=person.metadata&requestMask.includeField.paths=person.name&requestMask.includeField.paths=person.phone&requestMask.includeField.paths=person.photo&requestMask.includeField.paths=person.read_only_profile_info&requestMask.includeField.paths=person.organization&requestMask.includeField.paths=person.location&requestMask.includeField.paths=person.cover_photo&requestMask.includeContainer=PROFILE&requestMask.includeContainer=DOMAIN_PROFILE&requestMask.includeContainer=CONTACT&key=REDACTED'
```
第一眼看起来内容有很多,但是现在你不需要考虑每一行是什么意思。你只需要把不相关的行删掉就可以了。
我通常通过删掉某行查看是否有错误来验证该行是不是可以删除 —— 只要请求没有错误就一直删请求头。通常情况下,你可以删掉 `Accept*`、`Referer`、`Sec-*`、`DNT`、`User-Agent` 和缓存相关的头。
在这个例子中,我把请求删成下面的样子:
```
curl 'https://people-pa.clients6.google.com/v2/people/?key=REDACTED' \
-X POST \
-H 'Authorization: SAPISIDHASH REDACTED' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Origin: https://hangouts.google.com' \
-H 'Cookie: REDACTED'\
--data-raw 'personId=101777723309&personId=1175339043204&personId=1115266537043&personId=116731406166&extensionSet.extensionNames=HANGOUTS_ADDITIONAL_DATA&extensionSet.extensionNames=HANGOUTS_OFF_NETWORK_GAIA_GET&extensionSet.extensionNames=HANGOUTS_PHONE_DATA&includedProfileStates=ADMIN_BLOCKED&includedProfileStates=DELETED&includedProfileStates=PRIVATE_PROFILE&mergedPersonSourceOptions.includeAffinity=CHAT_AUTOCOMPLETE&coreIdParams.useRealtimeNotificationExpandedAcls=true&requestMask.includeField.paths=person.email&requestMask.includeField.paths=person.gender&requestMask.includeField.paths=person.in_app_reachability&requestMask.includeField.paths=person.metadata&requestMask.includeField.paths=person.name&requestMask.includeField.paths=person.phone&requestMask.includeField.paths=person.photo&requestMask.includeField.paths=person.read_only_profile_info&requestMask.includeField.paths=person.organization&requestMask.includeField.paths=person.location&requestMask.includeField.paths=person.cover_photo&requestMask.includeContainer=PROFILE&requestMask.includeContainer=DOMAIN_PROFILE&requestMask.includeContainer=CONTACT&key=REDACTED'
```
这样我只需要 4 个请求头:`Authorization`、`Content-Type`、`Origin` 和 `Cookie`。这样容易管理得多。
### 第四步:在 Python 中发请求
现在我们知道了我们需要哪些请求头,我们可以把 `curl` 命令翻译进 Python 程序!这部分是相当机械化的过程,目标仅仅是用 Python 发送与 curl 相同的数据。
下面是代码实例。我们使用 Python 的 `requests` 包实现了与前面 `curl` 命令相同的功能。我把整个长请求分解成了元组的数组,以便看起来更简洁。
```
import requests
import urllib
data = [
('personId','101777723'), # I redacted these IDs a bit too
('personId','117533904'),
('personId','111526653'),
('personId','116731406'),
('extensionSet.extensionNames','HANGOUTS_ADDITIONAL_DATA'),
('extensionSet.extensionNames','HANGOUTS_OFF_NETWORK_GAIA_GET'),
('extensionSet.extensionNames','HANGOUTS_PHONE_DATA'),
('includedProfileStates','ADMIN_BLOCKED'),
('includedProfileStates','DELETED'),
('includedProfileStates','PRIVATE_PROFILE'),
('mergedPersonSourceOptions.includeAffinity','CHAT_AUTOCOMPLETE'),
('coreIdParams.useRealtimeNotificationExpandedAcls','true'),
('requestMask.includeField.paths','person.email'),
('requestMask.includeField.paths','person.gender'),
('requestMask.includeField.paths','person.in_app_reachability'),
('requestMask.includeField.paths','person.metadata'),
('requestMask.includeField.paths','person.name'),
('requestMask.includeField.paths','person.phone'),
('requestMask.includeField.paths','person.photo'),
('requestMask.includeField.paths','person.read_only_profile_info'),
('requestMask.includeField.paths','person.organization'),
('requestMask.includeField.paths','person.location'),
('requestMask.includeField.paths','person.cover_photo'),
('requestMask.includeContainer','PROFILE'),
('requestMask.includeContainer','DOMAIN_PROFILE'),
('requestMask.includeContainer','CONTACT'),
('key','REDACTED')
]
response = requests.post('https://people-pa.clients6.google.com/v2/people/?key=REDACTED',
headers={
'X-HTTP-Method-Override': 'GET',
'Authorization': 'SAPISIDHASH REDACTED',
'Content-Type': 'application/x-www-form-urlencoded',
'Origin': 'https://hangouts.google.com',
'Cookie': 'REDACTED',
},
data=urllib.parse.urlencode(data),
)
print(response.text)
```
我执行这个程序后正常运行 —— 输出了一堆 JSON 数据!太棒了!
你会注意到有些地方我用 `REDACTED` 代替了,因为如果我把原始数据列出来你就可以用我的账号来访问谷歌论坛了,这就很不好了。
### 运行结束!
现在我可以随意修改 Python 程序,比如传入不同的参数,或解析结果等。
我不打算用它来做其他有意思的事了,因为我压根对这个 API 没兴趣,我只是用它来阐述请求 API 的过程。
但是你确实可以对返回的一堆 JSON 做一些处理。
### curlconverter 看起来很强大
有人评论说可以使用<https://curlconverter.com/>自动把 curl 转换成 Python和一些其他的语言这看起来很神奇 —— 我都是手动转的。我在这个例子里使用了它,看起来一切正常。
### 追踪 API 的处理过程并不容易
我不打算夸大追踪 API 处理过程的难度 —— API 的处理过程并不明显!我也不知道传给这个谷歌论坛 API 的一堆参数都是做什么的!
但是有一些参数看起来很直观,比如 `requestMask.includeField.paths=person.email` 可能表示”包含每个人的邮件地址“。因此我只关心我能看懂的参数,不关心看不懂的。
### (理论上)适用于所有场景
可能有人质疑 —— 这个方法适用于所有场景吗?
答案是肯定的 —— 浏览器不是魔法!浏览器发送给你的服务器的所有信息都是 HTTP 请求。因此如果我复制了浏览器发送的所有的 HTTP 请求头,那么后端就会认为请求是从我的浏览器发出的,而不是用 Python 程序发出的。
当然,我们去掉了一些浏览器发送的请求头,因此理论上后端是可以识别出来请求是从浏览器还是 Python 程序发出的,但是它们通常不会检查。
这里有一些对读者的告诫 —— 一些谷歌服务的后端会通过令人难以理解(对我来说是)方式跟前端通信,因此即使理论上你可以模拟前端的请求,但实际上可能行不通。可能会遭受更多攻击的大型 API 会有更多的保护措施。
我们已经知道了如何调用没有文档说明的 API。现在我们再来聊聊可能遇到的问题。
### 问题 1session cookies 过期
一个大问题是我用我的谷歌 session cookie 作为身份认证,因此当我的浏览器 session 过期后,这个脚本就不能用了。
这意味着这种方式不能长久使用(我宁愿调一个真正的 API但是如果我只是要一次性快速抓取一小组数据那么可以使用它。
### 问题 2滥用
如果我正在请求一个小网站,那么我的 Python 脚本可能会把服务打垮,因为请求数超出了它们的处理能力。因此我请求时尽量谨慎,尽量不过快地发送大量请求。
这尤其重要,因为没有官方 API 的网站往往是些小网站且没有足够的资源。
很明显在这个例子中这不是问题 —— 我认为在写这篇文章的过程我一共向谷歌论坛的后端发送了 20 次请求,他们肯定可以处理。
如果你用自己的账号资格过度访问这个 API 并导致了故障,那么你的账号可能(情理之中)会被暂时封禁。
我只下载我自己的数据或公共的数据 —— 我的目的不是寻找网站的弱点。
### 请记住所有人都可以访问你没有文档说明的 API
我认为本文最重要的信息并不是如何使用其他人没有文档说明的 API。虽然很有趣但是也有一些限制而且我也不会经常这么做。
更重要的一点是,任何人都可以这么访问你后端的 API每个人都有开发者工具和网络标签查看你传到后端的参数、修改它们都很容易。
因此如果一个人通过修改某些参数来获取其他用户的信息,这不值得提倡。我认为提供公开 API 的大部分开发者们都知道,但是我之所以再提一次,是因为每个初学者都应该了解。:)
--------------------------------------------------------------------------------
via: https://jvns.ca/blog/2022/03/10/how-to-use-undocumented-web-apis/
作者:[Julia Evans][a]
选题:[lujun9972][b]
译者:[lxbwolf](https://github.com/lxbwolf)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://jvns.ca/
[b]: https://github.com/lujun9972
[1]: https://jvns.ca/blog/2022/03/08/tiny-programs/
[2]: https://jvns.ca/images/network-tab.png