python 正确下载ftp文件
我正在尝试在内存中写入一个类似对象的文件。 我在 ftp 上下载了一个文件,当我尝试使用 read 方法将其转换为 StringIO 或 BytesIO 对象时,我得到以下信息:
"Android 4.2.2 Google Play 4 GB Bluetooth Dubbele sim & dubbele stand-by Simlockvrij Scherm: 4.0"" OLED nHD multi-touch Processor: Dual-Core Cortex A7 1,3 GHz Mobiele data/3G: HSDPA 7.2 Mbps / HSUPA";90,720000;3,00000000;,00000000;1,00000000;;ANDROID e ACCESSORI;SMARTPHONE e LED e PRODOTTI COOL;ACCESSORI TABLET e SMARTPHONE;,1100000000;,2000000000;,1000000000;1,0000000000;https://x-yasmp40200_u.jpg;https://x2/00000000000000005268-art-icol-yasmp40200_u.jpg;888888888;2,00000000\r\n'
这是代码:
with closing(request.urlopen("ftp://{}:{}@ftp.url/file.csv".format(USERNAME, PASSWORD))) as r:
b = io.BytesIO(r.read())
print(b.read())
为什么 \r\n 字符转换为字符串,并且是 ' 字符逃走了? 如何正确获取文件内容?
I am trying to write a file like object in memory.
I downloaded a file on ftp and when I try to convert it to a StringIO or BytesIO object using the method read I am getting this:
"Android 4.2.2 Google Play 4 GB Bluetooth Dubbele sim & dubbele stand-by Simlockvrij Scherm: 4.0"" OLED nHD multi-touch Processor: Dual-Core Cortex A7 1,3 GHz Mobiele data/3G: HSDPA 7.2 Mbps / HSUPA";90,720000;3,00000000;,00000000;1,00000000;;ANDROID e ACCESSORI;SMARTPHONE e LED e PRODOTTI COOL;ACCESSORI TABLET e SMARTPHONE;,1100000000;,2000000000;,1000000000;1,0000000000;https://x-yasmp40200_u.jpg;https://x2/00000000000000005268-art-icol-yasmp40200_u.jpg;888888888;2,00000000\r\n'
This is the code:
with closing(request.urlopen("ftp://{}:{}@ftp.url/file.csv".format(USERNAME, PASSWORD))) as r:
b = io.BytesIO(r.read())
print(b.read())
Why are the \r\n chars converted to a string and is the ' char escaped?
How to properly get the file content?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现正确的编码格式是
iso-8859-1
:I discovered that the right encoding format is
iso-8859-1
: