在之前的文章中,我们学习在[Python中使用Requests访问STEEM RPC](https://steemit.com/python/@oflyhigh/python-requests-steem-rpc)、[Python中使用urllib访问STEEM RPC](https://steemit.com/python/@oflyhigh/python-urllib-steem-rpc)、[Python中使用PycURL访问STEEM RPC](https://steemit.com/pycurl/@oflyhigh/python-pycurl-steem-rpc),原本这三把板斧足够我用了,但是阅读好些代码都是用的urllib3,所以拿来试试啦。  (图源:[bing.com](https://bing.com)) # 介绍 urllib3是一个强大的、健全友好的Python HTTP客户端,包括requests、pip在内的很多Python生态系统都使用了urllib3。 urllib3具有如下特性: * 线程安全 * 连接池 * 客户端SSL/TLS校验 * 多部分编码文件上传 * 请求重试以及HTTP重定向 * gzip以及deflate编码 * HTTP以及SOCKS代理 * 100%测试覆盖 # 安装 urllib3是第三方的库,所以使用之前需要先安装。 pip安装的指令为: `pip install urllib3` 因为我安装过requests,所以会提示我已经安装啦。 # 代码 继续拿我们之前的命令为例来学习: >`curl --data '{"jsonrpc": "2.0", "method": "call", "params": ["account_by_key_api", "get_key_references", [["STM6MGdForcZ8HskcguP84QSCb8udgz7W9yUPU5jtsAKQAxth3U16"]]], "id": 1}' https://api.steemit.com` 使用urllib3改写后的简单代码为: ``` import urllib3 import json payload = {"jsonrpc": "2.0", "method": "call", "params": ["account_by_key_api", "get_key_references", [["STM6MGdForcZ8HskcguP84QSCb8udgz7W9yUPU5jtsAKQAxth3U16"]]], "id": 1} rpc = "https://api.steemit.com" http = urllib3.PoolManager() r = http.request('POST', rpc, body=json.dumps(payload).encode('utf-8')) print(r.data.decode('utf-8')) ``` # 结果 执行结果为: >`InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings InsecureRequestWarning) {"id":1,"result":[["oflyhigh"]]}` 加上这样一句就好啦 `urllib3.disable_warnings()`  但是实际使用中,不校验证书是不安全、不被提倡的做法。如何校验证书,将在其它文章中另行阐述。 # 高级功能 类似keep-alive等高级功能可以通过在构建urllib3.PoolManager类实例时通过参数指定。 \******************************************************** 比如Keep-Alive功能,需要在上述代码中加入如下内容: ``` from urllib3.connection import HTTPConnection socket_options = HTTPConnection.default_socket_options + \ [(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1), ] http = urllib3.poolmanager.PoolManager(socket_options=socket_options) ``` \********************************************************* ***注:这段代码我理解有误,并非用于实现Keep-Alive功能*** 更多功能和详情,参考用户手册吧。 # 参考链接 * https://urllib3.readthedocs.io/en/latest/index.html * [每天进步一点点:Python中使用PycURL访问STEEM RPC](https://steemit.com/pycurl/@oflyhigh/python-pycurl-steem-rpc) * [每天进步一点点:Python中使用urllib访问STEEM RPC](https://steemit.com/python/@oflyhigh/python-urllib-steem-rpc) * [每天进步一点点:Python中使用Requests访问STEEM RPC](https://steemit.com/python/@oflyhigh/python-requests-steem-rpc)
author | oflyhigh |
---|---|
permlink | python-urllib3-steem-rpc |
category | python |
json_metadata | {"tags":["python","urllib3","steem","cn-programming","cn"],"image":["https://steemitimages.com/DQmXQzDMbiUMFVUWX8A9qodarzSPfjvgJH9NufV46enHncb/image.png","https://steemitimages.com/DQmWxUdaVa77QNb3WRXooSitp7dyTipXUhwFZos1sfgUm4v/image.png"],"links":["https://steemit.com/python/@oflyhigh/python-requests-steem-rpc","https://steemit.com/python/@oflyhigh/python-urllib-steem-rpc","https://steemit.com/pycurl/@oflyhigh/python-pycurl-steem-rpc","https://bing.com","https://urllib3.readthedocs.io/en/latest/index.html"],"app":"steemit/0.1","format":"markdown"} |
created | 2018-02-25 13:33:09 |
last_update | 2018-03-01 10:58:36 |
depth | 0 |
children | 7 |
last_payout | 2018-03-04 13:33:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 96.658 HBD |
curator_payout_value | 17.413 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 2,694 |
author_reputation | 6,384,147,372,083,281 |
root_title | "每天进步一点点:Python中使用urllib3访问STEEM RPC" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 40,336,974 |
net_rshares | 20,588,441,893,685 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
pharesim | 0 | 91,195,508,254 | 0.09% | ||
abit | 0 | 2,734,346,700,105 | 100% | ||
bue | 0 | 13,935,251,433 | 100% | ||
mark-waser | 0 | 103,803,637,236 | 100% | ||
slowwalker | 0 | 2,276,541,350,915 | 16% | ||
vi1son | 0 | 125,648,006,983 | 100% | ||
blockchainbilly | 0 | 21,923,133,446 | 50% | ||
fundurian | 0 | 14,131,800,985 | 30% | ||
deanliu | 0 | 1,275,304,860,187 | 100% | ||
rea | 0 | 2,082,917,933,157 | 100% | ||
ace108 | 0 | 256,017,798,296 | 25% | ||
laoyao | 0 | 34,990,307,911 | 100% | ||
somebody | 0 | 1,258,750,546,322 | 100% | ||
warofcraft | 0 | 96,892,554,854 | 50% | ||
xiaohui | 0 | 837,604,384,845 | 100% | ||
oflyhigh | 0 | 2,239,559,335,023 | 100% | ||
xiaokongcom | 0 | 10,219,761,657 | 100% | ||
rivalhw | 0 | 259,428,159,960 | 20% | ||
chinadaily | 0 | 166,002,412,076 | 100% | ||
helene | 0 | 552,748,871,701 | 100% | ||
ffcrossculture | 0 | 18,106,961,696 | 100% | ||
ethansteem | 0 | 193,688,020,035 | 100% | ||
englishtchrivy | 0 | 37,357,165,592 | 12% | ||
davidjkelley | 0 | 5,257,073,819 | 100% | ||
digital-wisdom | 0 | 57,046,047,874 | 100% | ||
ethical-ai | 0 | 18,858,215,723 | 100% | ||
jwaser | 0 | 21,916,610,564 | 100% | ||
profitgenerator | 0 | 1,287,792,892 | 100% | ||
damarth | 0 | 239,559,618,574 | 3% | ||
bwaser | 0 | 3,187,509,111 | 100% | ||
jianghao | 0 | 231,676,028 | 10% | ||
ellepdub | 0 | 1,663,870,979 | 100% | ||
herpetologyguy | 0 | 258,507,903,464 | 100% | ||
morgan.waser | 0 | 7,847,315,399 | 100% | ||
handyman | 0 | 2,520,759,759 | 100% | ||
amylee | 0 | 74,000,696,598 | 100% | ||
mrtv2 | 0 | 60,321,396,274 | 100% | ||
strong-ai | 0 | 16,027,078,849 | 100% | ||
steemtruth | 0 | 24,415,160,024 | 10% | ||
lalala | 0 | 48,885,173,070 | 100% | ||
dapeng | 0 | 27,258,558,850 | 25% | ||
abraomarcos | 0 | 2,392,598,688 | 100% | ||
lydiachan | 0 | 29,446,906,725 | 100% | ||
technoprogressiv | 0 | 12,203,553,068 | 100% | ||
newhope | 0 | 1,813,508,306,120 | 23% | ||
dragon40 | 0 | 2,356,443,117 | 10% | ||
blackbunny | 0 | 58,862,792,770 | 100% | ||
chessmasterhex | 0 | 1,631,095,439 | 100% | ||
bxt | 0 | 165,351,442,042 | 100% | ||
lingfei | 0 | 40,346,468,378 | 100% | ||
yyyy | 0 | 450,469,190 | 100% | ||
alexis555 | 0 | 1,434,853,566,938 | 21% | ||
ygern | 0 | 9,853,262,684 | 26% | ||
trafalgar | 0 | 805,615,159,004 | 3% | ||
austinsandersco | 0 | 780,364,216 | 70% | ||
kingofdew | 0 | 44,289,716,770 | 100% | ||
emcvay | 0 | 176,708,142 | 10% | ||
sacred-agent | 0 | 18,771,898,439 | 17% | ||
mandagoi | 0 | 10,255,945,232 | 21% | ||
ribalinux | 0 | 4,520,180,109 | 10% | ||
wylo | 0 | 613,964,238 | 100% | ||
susanlo | 0 | 47,030,991,362 | 100% | ||
jkkim | 0 | 53,013,196 | 10% | ||
ebejammin | 0 | 6,077,757,951 | 100% | ||
nanosesame | 0 | 22,345,264,291 | 30% | ||
cryptohustler | 0 | 7,991,888,883 | 100% | ||
exec | 0 | 80,879,219,745 | 100% | ||
eval | 0 | 792,987,799 | 100% | ||
michaelwilshaw | 0 | 4,246,734,513 | 10% | ||
speeding | 0 | 3,701,373,309 | 100% | ||
frankchen | 0 | 549,980,888 | 100% | ||
szh7379 | 0 | 614,503,071 | 100% | ||
motormouth | 0 | 190,211,260 | 100% | ||
walkinharmony | 0 | 18,028,465,322 | 50% | ||
asterix87 | 0 | 11,651,960,937 | 100% | ||
marram | 0 | 1,642,931,173 | 100% | ||
abetterworld | 0 | 3,154,877,973 | 100% | ||
that1consultant | 0 | 302,271,763 | 100% | ||
sanzo | 0 | 319,727,200 | 100% | ||
davaowhenyo | 0 | 614,503,785 | 100% | ||
allenshayzar | 0 | 614,503,785 | 100% | ||
travelgirl | 0 | 40,958,679,454 | 33% | ||
camilomango | 0 | 402,499,979 | 100% | ||
raku | 0 | 613,122,478 | 100% | ||
resteeming | 0 | 614,860,000 | 100% | ||
ravenousappetite | 0 | 614,503,440 | 100% | ||
aabb | 0 | 11,821,428,920 | 100% | ||
auntigormint | 0 | 537,652,272 | 100% | ||
mrliga | 0 | 12,808,834,659 | 100% | ||
twinkledrop | 0 | 106,006,331,859 | 100% | ||
sweethoney | 0 | 253,884,794 | 100% | ||
liangfengyouren | 0 | 1,091,591,538 | 50% | ||
idx | 0 | 21,694,377,908 | 100% | ||
chaofanjun | 0 | 6,046,547,069 | 100% | ||
exprmnt | 0 | 509,712,557 | 100% | ||
lancy | 0 | 4,928,888,544 | 92% | ||
bearpaw | 0 | 2,491,466,048 | 100% | ||
freedom-fighter | 0 | 614,503,785 | 100% | ||
technologynepal | 0 | 613,122,478 | 100% | ||
rosatravels | 0 | 18,629,277,026 | 20% | ||
dgorbunov | 0 | 533,802,377 | 100% | ||
tiffanyrej | 0 | 2,788,778,010 | 100% | ||
khalilad | 0 | 615,320,000 | 100% | ||
ms8988 | 0 | 609,328,864 | 100% | ||
yingpingzhang | 0 | 13,274,966,598 | 100% | ||
xiaoshancun | 0 | 510,326,304 | 100% | ||
stakuza | 0 | 615,483,841 | 100% | ||
dennisphillips | 0 | 73,574,697 | 25% | ||
ikonik | 0 | 514,933,812 | 100% | ||
vfxness | 0 | 67,564,598 | 100% | ||
lemminon | 0 | 615,320,000 | 100% | ||
heyeshuang | 0 | 640,969,078 | 100% | ||
razor80 | 0 | 605,677,464 | 100% | ||
fastiduos | 0 | 615,320,000 | 100% | ||
ivysrono | 0 | 1,006,406,205 | 100% | ||
rebecca80 | 0 | 615,502,093 | 100% | ||
nitro.live | 0 | 14,221,528,924 | 100% | ||
chaerin | 0 | 604,121,279 | 100% | ||
simivalleyjeff53 | 0 | 488,638,721 | 100% | ||
cnbuddy | 0 | 4,430,749,695 | 0.1% | ||
chann | 0 | 3,729,789,104 | 10% | ||
yammyamm | 0 | 236,680,052 | 100% | ||
quantum-bug | 0 | 484,364,298 | 100% | ||
devart | 0 | 260,702,102 | 100% | ||
lebin | 0 | 31,314,362,831 | 50% | ||
riad789 | 0 | 601,294,632 | 100% | ||
saury | 0 | 259,305,253 | 100% | ||
candiru | 0 | 339,997,350 | 100% | ||
quicksnake | 0 | 433,800,600 | 100% | ||
patrickzhou | 0 | 14,040,178,665 | 100% | ||
ewq | 0 | 728,133,775 | 3% | ||
neexal | 0 | 81,700,366 | 100% | ||
us1 | 0 | 178,373,325 | 100% | ||
benytg | 0 | 487,022,954 | 100% | ||
charisma1 | 0 | 243,940,876 | 100% | ||
historylover | 0 | 521,171,808 | 100% | ||
azharihasansteem | 0 | 413,818,142 | 100% | ||
akpa | 0 | 558,375,007 | 100% | ||
leshiyma | 0 | 458,777,507 | 100% | ||
dedanfed | 0 | 594,573,962 | 100% | ||
bxl9426 | 0 | 602,159,130 | 100% | ||
tteaays | 0 | 556,240,674 | 100% | ||
btccurrency1 | 0 | 52,390,265 | 100% | ||
ethanlee | 0 | 15,012,248,502 | 100% | ||
amponchiek | 0 | 61,826,301 | 100% | ||
sibehgeng | 0 | 397,970,399 | 100% | ||
fanso | 0 | 468,812,777 | 100% | ||
cryptoknight27 | 0 | 615,076,421 | 100% | ||
nilsss | 0 | 583,739,061 | 100% | ||
dani123 | 0 | 147,232,319 | 100% | ||
martijnephraim | 0 | 1,595,734,406 | 70% | ||
munnapandey | 0 | 52,329,200 | 100% | ||
leeyoonji | 0 | 556,077,023 | 100% | ||
chinaculture | 0 | 83,167,195 | 100% |
Muy bueno, amigo, te seguiré aunque estés en otro idioma
author | carlosgerdet |
---|---|
permlink | re-oflyhigh-python-urllib3-steem-rpc-20180225t193255627z |
category | python |
json_metadata | {"tags":["python"],"app":"steemit/0.1"} |
created | 2018-02-25 19:06:33 |
last_update | 2018-02-25 19:06:33 |
depth | 1 |
children | 0 |
last_payout | 2018-03-04 19:06:33 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 56 |
author_reputation | 273,164,074,193 |
root_title | "每天进步一点点:Python中使用urllib3访问STEEM RPC" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 40,403,037 |
net_rshares | 0 |
all commands are useful and easy
author | farah-kamran |
---|---|
permlink | re-oflyhigh-python-urllib3-steem-rpc-20180225t133513478z |
category | python |
json_metadata | {"tags":["python"],"app":"steemit/0.1"} |
created | 2018-02-25 13:35:21 |
last_update | 2018-02-25 13:35:21 |
depth | 1 |
children | 0 |
last_payout | 2018-03-04 13:35:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 32 |
author_reputation | 175,703,680,965 |
root_title | "每天进步一点点:Python中使用urllib3访问STEEM RPC" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 40,337,425 |
net_rshares | 0 |
Good luck @oflyhigh
author | hamidi103 | ||||||
---|---|---|---|---|---|---|---|
permlink | re-oflyhigh-2018225t21301723z | ||||||
category | python | ||||||
json_metadata | {"tags":["python","urllib3","steem","cn-programming","cn"],"app":"esteem/1.5.1","format":"markdown+html","community":"esteem"} | ||||||
created | 2018-02-25 14:30:09 | ||||||
last_update | 2018-02-25 14:30:09 | ||||||
depth | 1 | ||||||
children | 0 | ||||||
last_payout | 2018-03-04 14:30:09 | ||||||
cashout_time | 1969-12-31 23:59:59 | ||||||
total_payout_value | 0.000 HBD | ||||||
curator_payout_value | 0.000 HBD | ||||||
pending_payout_value | 0.000 HBD | ||||||
promoted | 0.000 HBD | ||||||
body_length | 19 | ||||||
author_reputation | 3,169,070,286,797 | ||||||
root_title | "每天进步一点点:Python中使用urllib3访问STEEM RPC" | ||||||
beneficiaries |
| ||||||
max_accepted_payout | 1,000,000.000 HBD | ||||||
percent_hbd | 10,000 | ||||||
post_id | 40,348,588 | ||||||
net_rshares | 0 |
Upvoted ☝ Have a great day!
author | hotpacks |
---|---|
permlink | re-oflyhigh-python-urllib3-steem-rpc-20180301t205100272z |
category | python |
json_metadata | "" |
created | 2018-03-01 11:51:21 |
last_update | 2018-03-01 11:51:21 |
depth | 1 |
children | 0 |
last_payout | 2018-03-08 11:51:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 27 |
author_reputation | -14,134,173,840 |
root_title | "每天进步一点点:Python中使用urllib3访问STEEM RPC" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 41,363,063 |
net_rshares | 0 |
Hy friend very very good post thanks for you
author | pengenkaya |
---|---|
permlink | re-oflyhigh-python-urllib3-steem-rpc-20180225t134533038z |
category | python |
json_metadata | {"tags":["python"],"app":"steemit/0.1"} |
created | 2018-02-25 13:45:39 |
last_update | 2018-02-25 13:45:39 |
depth | 1 |
children | 0 |
last_payout | 2018-03-04 13:45:39 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 44 |
author_reputation | 1,399,679,939,009 |
root_title | "每天进步一点点:Python中使用urllib3访问STEEM RPC" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 40,339,416 |
net_rshares | 0 |
Buen post! Gracias por compartir.
author | playnet |
---|---|
permlink | re-oflyhigh-python-urllib3-steem-rpc-20180225t184049589z |
category | python |
json_metadata | {"tags":["python"],"app":"steemit/0.1"} |
created | 2018-02-25 18:41:15 |
last_update | 2018-02-25 18:41:15 |
depth | 1 |
children | 0 |
last_payout | 2018-03-04 18:41:15 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 33 |
author_reputation | 5,139,860,917 |
root_title | "每天进步一点点:Python中使用urllib3访问STEEM RPC" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 40,398,450 |
net_rshares | 0 |
Very good picture and your story
author | zulfikrizal |
---|---|
permlink | re-oflyhigh-python-urllib3-steem-rpc-20180225t140135429z |
category | python |
json_metadata | {"tags":["python"],"app":"steemit/0.1"} |
created | 2018-02-25 14:01:45 |
last_update | 2018-02-25 14:01:45 |
depth | 1 |
children | 0 |
last_payout | 2018-03-04 14:01:45 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 32 |
author_reputation | 12,742,438,086 |
root_title | "每天进步一点点:Python中使用urllib3访问STEEM RPC" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 40,342,696 |
net_rshares | 0 |