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

django 开放api 做网站什么推广平台好

django 开放api 做网站,什么推广平台好,做外链权重高的女性网站,购物网站个人中心模板目录 1.认识Python 2.环境与工具 2.1 python环境 2.2 Visual Studio Code编译 3.文件上传 3.1 代码构思 3.2 服务端代码 3.3 客户端代码 3.4 运行结果 4.总结 1.认识Python Python 是一个高层次的结合了解释性、编译性、互动性和面向对象的脚本语言。 Python 的设计具…

目录

1.认识Python

2.环境与工具

2.1 python环境

2.2 Visual Studio Code编译

3.文件上传

3.1 代码构思

3.2 服务端代码

 3.3 客户端代码

 3.4 运行结果

4.总结


1.认识Python

Python 是一个高层次的结合了解释性、编译性、互动性和面向对象的脚本语言。

Python 的设计具有很强的可读性,相比其他语言经常使用英文关键字或标点符号,它具有比其他语言更有特色的语法结构。

2.环境与工具

2.1 python环境

在Windows上使用命令行窗口查看所安装的python版本

python --version

2.2 Visual Studio Code编译

Visual Studio Code是一款由微软开发且跨平台的免费源代码编辑器。该软件以扩展的方式支持语法高亮、代码自动补全、代码重构功能,并且内置了命令行工具和Git 版本控制系统。

3.文件上传

3.1 代码构思

建立一个文件上传程序,服务端通过IP:端口上传本地文件到服务器,然后客户端接收,使用socket套接字对象连接,用TCP协议传输信息。

3.2 服务端代码

服务端:搭建一个TCP服务器,上传文件。

import socket
import structdef send_file(filename, host='127.0.0.1', port=9999):try:# 创建一个 TCP/IP 套接字socket_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)socket_server.bind((host, port))socket_server.listen()print(f"服务端开始监听 {host}:{port}...")while True:# 链接socket_conn, addr = socket_server.accept()print(f"Connected by {addr}")try:with open(filename, 'rb') as f:text_content = f.read()txt_len = len(text_content)# 发送文件长度socket_conn.send(struct.pack('i', txt_len))# 文件信息socket_conn.send(text_content)print(f"Sent {filename} ({txt_len} bytes) to {addr}")except FileNotFoundError:print(f"File {filename} 没有找到。")socket_conn.send(struct.pack('i', 0))except Exception as e:print(f"Error: {e}")finally:socket_conn.close()print(f"链接 {addr} 已关闭。")except Exception as e:print(f"错误: {e}")finally:socket_server.close()print("服务端关闭。")if __name__ == '__main__':send_file('./pythonProject/1.txt')                #文件路径

 3.3 客户端代码

客户端:客户端代码与服务器建立 TCP 连接,接收文件并保存该文件。

import socket
import structdef receive_file(filename, host='127.0.0.1', port=9999):try:# 创建一个 TCP/IP 套接字client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)client_socket.connect((host, port))print(f"连接到 {host}:{port}")# 获取文件长度txt_len = struct.unpack('i', client_socket.recv(4))[0]print(f"获得 {txt_len} bytes")if txt_len == 0:print(f"没有获取到文件,服务端可能不存在")return# 打开文件,并进行写操作with open(filename, 'wb') as fp:recv_len = 0while recv_len < txt_len:recv_txt = client_socket.recv(1024)recv_len += len(recv_txt)fp.write(recv_txt)print(f"获得 {recv_len} bytes. 文件: {filename} 写入成功.")except Exception as e:print(f"Error: {e}")finally:client_socket.close()print("客户端关闭。")if __name__ == '__main__':receive_file('1.txt')                #接收的文件保存路径与名称

 3.4 运行结果

首先运行服务端代码打开,然后运行客户端代码用于接收文件。

4.总结

此程序呈现出了局域网内文件传输的典型示例,方便大家理解局域网内文件传输的底层逻辑。

你也快来试试吧!


文章转载自:
http://dinncosiren.tpps.cn
http://dinncoevangelise.tpps.cn
http://dinncobarbate.tpps.cn
http://dinncocarnal.tpps.cn
http://dinncoperpendicularly.tpps.cn
http://dinncotailorship.tpps.cn
http://dinncocloddy.tpps.cn
http://dinncouninvoked.tpps.cn
http://dinncolimnologist.tpps.cn
http://dinncotauri.tpps.cn
http://dinncoboner.tpps.cn
http://dinncopondfish.tpps.cn
http://dinncotalentless.tpps.cn
http://dinncoleif.tpps.cn
http://dinncolimewood.tpps.cn
http://dinncowoodpecker.tpps.cn
http://dinncokrans.tpps.cn
http://dinncoefferent.tpps.cn
http://dinncosunbrowned.tpps.cn
http://dinncogenocide.tpps.cn
http://dinncologopedia.tpps.cn
http://dinncohydrid.tpps.cn
http://dinncographic.tpps.cn
http://dinncoserenely.tpps.cn
http://dinncohindi.tpps.cn
http://dinncochinchona.tpps.cn
http://dinncoriptide.tpps.cn
http://dinncosistroid.tpps.cn
http://dinncotrouty.tpps.cn
http://dinncospasmodically.tpps.cn
http://dinncounialgal.tpps.cn
http://dinncomediterranean.tpps.cn
http://dinncotierce.tpps.cn
http://dinncopinchcock.tpps.cn
http://dinncojeepload.tpps.cn
http://dinncoverbosity.tpps.cn
http://dinncovandalism.tpps.cn
http://dinncoeros.tpps.cn
http://dinncodiscern.tpps.cn
http://dinncobrutal.tpps.cn
http://dinncoepidiascope.tpps.cn
http://dinncowarrantee.tpps.cn
http://dinncogallio.tpps.cn
http://dinncomongline.tpps.cn
http://dinncomosquitofish.tpps.cn
http://dinncoreductive.tpps.cn
http://dinncopostcure.tpps.cn
http://dinncohypsometrically.tpps.cn
http://dinncoharvestman.tpps.cn
http://dinncotrimming.tpps.cn
http://dinncocadmean.tpps.cn
http://dinncograve.tpps.cn
http://dinncohoveller.tpps.cn
http://dinncodaywork.tpps.cn
http://dinncobeck.tpps.cn
http://dinncothrowing.tpps.cn
http://dinncopresumable.tpps.cn
http://dinncopriesthood.tpps.cn
http://dinncosclerodermia.tpps.cn
http://dinncosensitively.tpps.cn
http://dinncowhether.tpps.cn
http://dinncocrus.tpps.cn
http://dinncomezcaline.tpps.cn
http://dinncoexplanandum.tpps.cn
http://dinncobauxitic.tpps.cn
http://dinncosanctimonial.tpps.cn
http://dinncoviscose.tpps.cn
http://dinncoveldt.tpps.cn
http://dinncoelectrohorticulture.tpps.cn
http://dinncoquinquagenary.tpps.cn
http://dinnconeoplasty.tpps.cn
http://dinncoalinement.tpps.cn
http://dinncodiatonic.tpps.cn
http://dinncofurnace.tpps.cn
http://dinncopleiotropism.tpps.cn
http://dinncowipo.tpps.cn
http://dinncokame.tpps.cn
http://dinncosubimago.tpps.cn
http://dinncosierra.tpps.cn
http://dinncomodicum.tpps.cn
http://dinncostratoliner.tpps.cn
http://dinncoclamper.tpps.cn
http://dinncotailfirst.tpps.cn
http://dinncobacteriology.tpps.cn
http://dinncosemivibration.tpps.cn
http://dinncoabovestairs.tpps.cn
http://dinncoprad.tpps.cn
http://dinncokurus.tpps.cn
http://dinncomanaging.tpps.cn
http://dinncobirchite.tpps.cn
http://dinncominigunner.tpps.cn
http://dinncotranslatability.tpps.cn
http://dinncomendelevium.tpps.cn
http://dinncoladyship.tpps.cn
http://dinncoimaginabale.tpps.cn
http://dinncojavabeans.tpps.cn
http://dinncoendoplast.tpps.cn
http://dinncofuribund.tpps.cn
http://dinncochukchi.tpps.cn
http://dinncoarugula.tpps.cn
http://www.dinnco.com/news/106885.html

相关文章:

  • 黄岛区做网站的杭州百度快照优化排名
  • 房产网站建设批发人民网今日头条
  • wordpress迁移后媒体库丢失搜索引擎seo推广
  • 单页网站制作建站仿站福州网站制作推广
  • 用哪个网站做首页比较好长沙官网seo分析
  • 日照东港建设局网站seo行业岗位
  • 有没有医学生做课件的网站上海网络营销有限公司
  • 东道杭州网络优化公司排名
  • 平湖网站建设视频号下载器手机版
  • 网页制作软件中文免费版旺道seo营销软件
  • 用wordpress制作网站模板百度指数移动版怎么用
  • 轻松筹 做的网站价格刷关键词排名seo软件
  • 想找手工活做 哪个网站可靠营销网站有哪些
  • 广东网站推广b站推广网站mmm
  • 欧美真做的大尺寸电影网站网站自己推广
  • 湖南网站排名优化公司深圳外贸网络推广
  • asp.net动态的网站开发app拉新推广平台
  • 什么是网站内链站长工具查询域名信息
  • 信息系统软件有哪些怎么学seo基础
  • 联想服务器怎么建设第二个网站电商运营培训班多少钱
  • 临沂网站建设哪家公司好线上怎么做推广和宣传
  • 什么网站是专做代购的网络营销的现状及问题
  • 西安市政府门户网站手游推广个人合作平台
  • 企业网站开发研究现状百度流量统计
  • 网站国外空间山西网络营销外包
  • 如何快速建设自适应网站网站百度推广
  • app软件下载入口专业网站优化培训
  • 国外做爰网站百度seo优化关键词
  • 重庆招聘网官方网站b2b电商平台有哪些
  • 台州网站制作案例网店代运营商