当前位置: 首页 > news >正文

python pycurl 安装使用

python pycurl 安装使用

本文主要讲下pycurl 安装使用.

1.安装

首先使用 pip 命令安装.

pip install pycurl

输出如下:

Collecting pycurlUsing cached pycurl-7.45.2.tar.gz (234 kB)ERROR: Command errored out with exit status 1:command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-b8co1_ap/pycurl/setup.py'"'"'; __file__='"'"'/tmp/pip-install-b8co1_ap/pycurl/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-b8co1_ap/pycurl/pip-egg-infocwd: /tmp/pip-install-b8co1_ap/pycurl/Complete output (22 lines):Traceback (most recent call last):File "/tmp/pip-install-b8co1_ap/pycurl/setup.py", line 229, in configure_unixp = subprocess.Popen((self.curl_config(), '--version'),File "/usr/lib/python3.8/subprocess.py", line 858, in __init__self._execute_child(args, executable, preexec_fn, close_fds,File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_childraise child_exception_type(errno_num, err_msg, err_filename)FileNotFoundError: [Errno 2] No such file or directory: 'curl-config'During handling of the above exception, another exception occurred:Traceback (most recent call last):File "<string>", line 1, in <module>File "/tmp/pip-install-b8co1_ap/pycurl/setup.py", line 970, in <module>ext = get_extension(sys.argv, split_extension_source=split_extension_source)File "/tmp/pip-install-b8co1_ap/pycurl/setup.py", line 634, in get_extensionext_config = ExtensionConfiguration(argv)File "/tmp/pip-install-b8co1_ap/pycurl/setup.py", line 93, in __init__self.configure()File "/tmp/pip-install-b8co1_ap/pycurl/setup.py", line 234, in configure_unixraise ConfigurationError(msg)__main__.ConfigurationError: Could not run curl-config: [Errno 2] No such file or directory: 'curl-config'----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

解决安装失败的步骤如下:

  1. sudo apt-get install libcurl4-openssl-dev
  2. sudo apt-get install python-dev
  3. sudo apt-get install libssl-dev
  4. pip install pycurl

此时,可以看到安装成功.

Collecting pycurlUsing cached pycurl-7.45.2.tar.gz (234 kB)
Building wheels for collected packages: pycurlBuilding wheel for pycurl (setup.py) ... doneCreated wheel for pycurl: filename=pycurl-7.45.2-cp38-cp38-linux_x86_64.whl size=341360 sha256=xxxStored in directory: /home/zh/.cache/pip/wheels/07/65/79/xxx
Successfully built pycurl
Installing collected packages: pycurl
Successfully installed pycurl-7.45.2

2: 使用

pycurl是一个基于libcurl库的Python模块,它支持多种网络协议的,包括HTTP、HTTPS等。

使用pycurl可以进行网络请求、文件上传、下载等操作。

下面是使用get请求 , 访问百度. 并打印response.

#!/usr/bin/python3
# -*- coding: UTF-8 -*-
"""@Author: zh@Time 2023/12/22 下午12:56  .@Email:@Describe:
"""
import pycurl
# 创建一个Curl对象
curl = pycurl.Curl()
# 设置请求的URL
ccurlsetopt(curl.URL, 'http://www.baidu.com')
# 设置请求的方法为GET
curl.setopt(curl.HTTPGET, 1)
# 执行请求
curl.perform()# 获取响应内容
response = curl.getinfo(curl.RESPONSE_CODE)
print(response)# 关闭Curl对象
curl.close()
http://www.lryc.cn/news/264953.html

相关文章:

  • C语言数据结构-排序
  • Spring AOP入门指南:轻松掌握面向切面编程的基础知识
  • 【顶级快刊】IEEE(Trans),审稿快仅2个月录用,入选CCF-B,现在投最快!
  • 深入浅出堆排序: 高效算法背后的原理与性能
  • Golang实践录:gin绑定解析json的两种方法
  • Hypervisor Display架构
  • 基于ssm二手车交易平台的设计论文
  • IDEA 设置 SpringBoot logback 彩色日志(附配置文件)
  • 数学建模学习笔记-皮尔逊相关系数
  • 随笔:集成学习:关于随机森林,梯度提升机的东拉西扯
  • 多款实用个人年终总结模板,助力你的年度汇报!
  • 【C语言】动态内存管理基础知识——动态通讯录,如何实现通讯录容量的动态化
  • Centos9(Stream)配置Let‘s Encrypt (免费https证书)
  • Spring之事务(2)
  • 嵌入式科普(5)ARM GNU Toolchain相关概念和逻辑
  • Elasticsearch:什么是文本分类?
  • 指针(3)
  • 外汇天眼:我碰到外汇投资骗局了吗?学会这5招,轻松识别外汇诈骗黑平台!
  • 一文解析子网掩码和默认网关,成为网络设置达人
  • 二分查找法详解(6种变形)
  • uniapp uview 页面多个select组件回显处理,默认选中
  • linux中playbook的控制语句
  • MongoDB介绍
  • 再看参数校验
  • 计算机存储术语: 扇区,磁盘块,页
  • 解决IDEA编译/启动报错:Abnormal build process termination
  • Jetpack DataStore
  • 在Portainer创建Nginx容器并部署Web静态站点实现公网访问
  • 泛微e-cology XmlRpcServlet文件读取漏洞复现
  • 当下流行的直播技术demo演示