我正在使用以下代码,我传递.pdf文件名及其路径来创建zip文件.
for f in lstFileNames:
with zipfile.ZipFile('reportDir' + str(uuid.uuid4()) + '.zip', 'w') as myzip:
myzip.write(f)
Run Code Online (Sandbox Code Playgroud)
它只存档一个文件.我需要将列表中的所有文件归档到一个zip文件夹中.
在人们开始指出之前,是的,我已经从这个和这个链接咨询了答案,但那里给出的代码对我不起作用.代码运行但我无法在计算机的任何位置找到生成的zip文件.
一个简单明了的答案将不胜感激.谢谢.
在我的代码中,用户上传保存在服务器上并使用服务器路径读取的文件。阅读完文件后,我试图从该路径中删除该文件。但它给了我以下错误:
An error occurred while reading file. [WinError 32] The process cannot access the file because it is being used by another process
我正在使用 读取文件with,我已经尝试过f.close(),f.closed但每次都出现相同的错误。
这是我的代码:
f = open(filePath)
with f:
line = f.readline().strip()
tempLst = line.split(fileSeparator)
if(len(lstHeader) != len(tempLst)):
headerErrorMsg = "invalid headers"
hjsonObj["Line No."] = 1
hjsonObj["Error Detail"] = headerErrorMsg
data['lstErrorData'].append(hjsonObj)
data["status"] = True
f.closed
return data
f.closed
Run Code Online (Sandbox Code Playgroud)
在这段代码之后,我调用了删除函数:
os.remove(filePath)
Run Code Online (Sandbox Code Playgroud)
编辑:使用with open(filePath) as f:然后尝试删除文件会出现相同的错误。
有没有办法从放置在 dropzone 中的文件生成 zip,然后将该 zip 文件发送到服务器?
我是从文件中使用生成ZIPJSZip在sending悬浮窗的事件:
this.on("sending", function(file, xhr, formData) {
var zip = new JSZip();
zip.file("Hello.csv", file);
zip.generateAsync({ type: "blob" }).then(function(content) {
// see FileSaver.js
saveAs(content, "example.zip");
});
});
Run Code Online (Sandbox Code Playgroud)
如何让 dropzone 发送此文件而不是添加的一个用户?
request.FILES有没有办法像对待磁盘文件一样对待文件?我想做这样的事情:
with open(file_in_request, 'rb') as file:
#read data from that file
Run Code Online (Sandbox Code Playgroud)
只是,我不想先将其保存到磁盘。我将加密该文件并将加密的文件保存到磁盘。
我正在使用以下代码在的Python34应用程序中根据用户上传的文件创建受密码保护的zip文件zipFile。但是,当我从Windows打开zip文件时,它不会要求输入密码。稍后,我将使用相同的密码从python读取zip文件。我究竟做错了什么?
这是我的代码:
pwdZipFilePath = uploadFilePath + "encryptedZipFiles/"
filePath = uploadFilePath
if not os.path.exists(pwdZipFilePath):
os.makedirs(pwdZipFilePath)
#save csv file to a path
fd, filePath = tempfile.mkstemp(suffix=source.name, dir=filePath)
with open(filePath, 'wb') as dest:
shutil.copyfileobj(source, dest)
#convert that csv to zip
fd, pwdZipFilePath = tempfile.mkstemp(suffix=source.name + ".zip", dir=pwdZipFilePath)
with zipfile.ZipFile(pwdZipFilePath, 'w') as myzip:
myzip.write(filePath)
myzip.setpassword(b"tipi")
Run Code Online (Sandbox Code Playgroud) 我只需要根据月份和年份比较两个日期,而不考虑日期或时间。我尝试了以下操作,但没有给出正确的结果:
if lastMonthAllowed.month > lastUserUploadMonth.month and lastMonthAllowed.year > lastUserUploadMonth.year:
#do something
Run Code Online (Sandbox Code Playgroud)
有什么简单的方法可以实现这一目标吗?
我收到一个 JSON 对象,其中包含许多对象和对象列表等。在这些列表之一中是这样的 Year 列表:
[{'Year': '2015', 'Status': 'NR', 'Month': 'Jan'
{'Year': '2014', Status': '', 'Month': 'Jan'},
{'Year': '2015', 'Status': '',Month': 'Feb'},
{'Year': '2014', Status': '', 'Month': 'Feb'},
{'Year': '2015', 'Status': '', Month': 'Sep'},
{'Year': '2014', 'Status': 'OK', 'Month': 'Sep'},
{'Year': '2015', 'Status': '', 'Month': 'Oct'},
{'Year': '2014', 'Status': 'OK', 'Month': 'Oct'}]
Run Code Online (Sandbox Code Playgroud)
我需要按年份对这个列表进行分组,并根据年份显示月份。例如:
{"2015":[{"Month":"Jan", "Status":"NR"}, {"Month" : "Feb". "Status" :""}]
Run Code Online (Sandbox Code Playgroud)
现在,我使用的代码没有按照我想要的方式工作,而是根据月数重复年份:
2015
2014
2015
2014
2015
2014
2015
2014
Run Code Online (Sandbox Code Playgroud)
这是代码:
{% regroup x.LstPaymentBehaviour by Year as yearList %}
{% for …Run Code Online (Sandbox Code Playgroud) 我正在使用客户端发送 zip 文件的字节字符串,JSZip需要在服务器端将其转换回 zip。我试过的代码不起作用。
b = bytearray()
b.extend(map(ord, request.POST.get("zipFile")))
zipPath = 'uploadFile' + str(uuid.uuid4()) + '.zip'
myzip = zipfile.ZipFile(zipPath, 'w')
with myzip:
myzip.write(b)
Run Code Online (Sandbox Code Playgroud)
它给出了错误:
stat: path too long for Windows
Run Code Online (Sandbox Code Playgroud)
如何将我的字节字符串保存为 zip 文件?
我在 MVC Core 中创建了一个 API 项目。在我的控制器中,我添加了一些与 Postman 完美配合的 GET 和 POST 方法的 API。但是当我尝试从我的 Angular 应用程序调用它们时,它们给了我 CORS 错误:
从源访问 XMLHttpRequest 已被 CORS 策略阻止:请求的资源上不存在“Access-Control-Allow-Origin”标头
我用谷歌搜索解决方案,发现我需要添加 CORS NuGet 包。我这样做了,但错误仍然存在。
以下是我的Startup.cs文件代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using webapp1.Model;
namespace webapp1
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This …Run Code Online (Sandbox Code Playgroud) 我知道一旦浏览器下载了前端文件,就无法隐藏客户端的代码.但我听说也可以调试javascript代码,添加断点,跳过代码行(主要是安全检查)并按照自己的意愿操纵服务调用.
我正在开发的项目是在AngularJS中开发的,并使用SSL证书进行服务调用,但除此之外我如何在客户端添加安全性以保护我的代码不被操纵?
目前我的网址如下所示:
http://localhost:9737/ProfileEdit?writerId=4
Run Code Online (Sandbox Code Playgroud)
但我希望它是这样的:
http://localhost:9737/ProfileEdit/4
Run Code Online (Sandbox Code Playgroud)
这是我的行动签名:
public ActionResult ProfileEdit(long writerId)
Run Code Online (Sandbox Code Playgroud)
我尝试在RouteConfig文件中添加新路由,如下所示:
routes.MapRoute(
name: "ProfileEdit",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "ProfileEdit", writerId = UrlParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)
但没有运气..所以如何更改URL格式?
python ×7
django ×3
javascript ×2
python-3.x ×2
zipfile ×2
angular ×1
angularjs ×1
api ×1
asp.net-core ×1
asp.net-mvc ×1
c# ×1
cors ×1
dropzone.js ×1
file ×1
ssl ×1
zip ×1