我的 Flask 应用程序由 Heroku 托管并在 Nginx 上提供服务,并使用 Cloudflare 作为 CDN。有时我会更改后端的静态资产(图像、CSS、JS 等),这些资产通过在 Heroku 上的部署而改变。这些更改不会在客户端浏览器上更改,除非他们手动清除缓存。缓存确实按照建议每个月在客户端浏览器上过期,但我希望后端每次我部署到 Heroku 时都手动告诉客户端浏览器清除我网站的缓存,并且他们在事后加载/重新加载我的网站。有没有办法自动化这个过程?
我正在将 Unity 中构建的 WebGL 游戏嵌入到 Flask 中构建的 Web 应用程序中。我在后端使用 CSP 来实现安全目的,但即使wasm-eval在我的 CSP 中包含该指令后,我仍然仅在 Chrome 中收到这些错误:
UnityLoader.js:4 failed to asynchronously prepare wasm: CompileError: WebAssembly.instantiate(): Wasm code generation disallowed by embedder
printErr @ UnityLoader.js:4
UnityLoader.js:4 CompileError: WebAssembly.instantiate(): Wasm code generation disallowed by embedder
at blob:http://localhost:5000/510c750f-1181-4d80-926f-dc71e527c16b:8:31195
Uncaught (in promise) abort({}) at Error
at jsStackTrace (blob:http://localhost:5000/cd04e961-d5f5-490c-8869-fbc73dd40aa4:8:22295)
at Object.stackTrace (blob:http://localhost:5000/cd04e961-d5f5-490c-8869-fbc73dd40aa4:8:22466)
at Object.onAbort (http://localhost:5000/static/desert_run/Build/UnityLoader.js:4:11118)
at abort (blob:http://localhost:5000/cd04e961-d5f5-490c-8869-fbc73dd40aa4:8:446869)
at blob:http://localhost:5000/cd04e961-d5f5-490c-8869-fbc73dd40aa4:8:31316
Run Code Online (Sandbox Code Playgroud)
我不确定我需要修复什么,并且该unsafe-eval指令script-src也不起作用。这是我的 CSP 以及我在 _ init _.py 中使用的在后端实现它的代码:
from flask import …Run Code Online (Sandbox Code Playgroud) python google-chrome flask content-security-policy unity-webgl
我正在为我的 Flask 应用程序使用 Flask-Mail 库,以便在用户注册添加到时事通讯时向他们发送默认的欢迎电子邮件。调试该库后,我发现它一次只能处理一个连接来发送消息,然后会自动关闭连接。如果后端将电子邮件发送到另一个用户同时连接仍处于打开状态则引发此异常:raise SMTPServerDisconnected("Connection unexpectedly closed: " smtplib.SMTPServerDisconnected: Connection unexpectedly closed: [WinError 10054] An existing connection was forcibly closed by the remote host。我希望能够在连接关闭后将邮件 Mail 库排队以向另一个收件人发送新消息,但目前当我尝试将函数排队以发送消息时,它不断抛出我上面提到的错误。
工人.py:
import os
import redis
from rq import Worker, Queue, Connection
listen = ['high', 'default', 'low']
redis_url = os.environ.get('REDISTOGO_URL')
conn = redis.from_url(redis_url)
if __name__ == '__main__':
with Connection(conn):
worker = Worker(map(Queue, listen))
worker.work()
Run Code Online (Sandbox Code Playgroud)
用户路由.py
from flask import request, Blueprint, redirect, render_template
from flask_app import mail, db
from flask_app.users.forms import NewsLetterRegistrationForm
from …Run Code Online (Sandbox Code Playgroud) 我正在开发一个 Flask 应用程序,它使用 Flask-Talisman 来合并 CSP。我想在我的模板之一中创建一个内联脚本,而不是将“unsafe-inline”添加到 CSP 的“script-src”数组中(这可能对 XSS 攻击有害),我想使用哈希或允许脚本运行的随机数。我复制了 Opera 开发工具中控制台错误消息中给出的哈希值,并将其放入 CSP 的“script-src”数组中(在init .py 文件中)。但是,由于某种原因,CSP 不会接受哈希值,我不知道如何修复它。我也用随机数尝试过,也出现了同样的问题。这是控制台输出(出于安全原因我删除了哈希值):
The source list for Content Security Policy directive 'script-src' contains an invalid source: 'sha256-(hash goes here)'.
It will be ignored.
Run Code Online (Sandbox Code Playgroud)
这是init .py中的 CSP :
csp = {
"default-src": [
"'self'",
'https://www.youtube.com',
'https://img.youtube.com'
],
'script-src': [ 'sha256-(hash goes here)',
'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js',
'https://code.jquery.com/jquery-3.3.1.slim.min.js',
'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js'],
'style-src': ["'self'",'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css']
}
Run Code Online (Sandbox Code Playgroud) python hashcode inline-scripting flask content-security-policy
我已经按照文档/教程了解如何从此处设置 RTMP 流的配置文件: https: //www.nginx.com/blog/video-streaming-for-remote-learning-with-nginx/及其非常简单。但是,我不确定如何在 Flask 上构建后端,以将流重定向到嵌入 HTML 模板中的某个 HLS/DASH 视频播放器,该模板是为了响应请求特定 HTTP 端点的客户端而发送的。本教程展示了如何在 VLC 媒体播放器中本地查看,但没有展示如何将其嵌入到发送到客户端的 HTML 文件中。我该怎么做呢?作为参考,我在 Heroku 上托管我的网站,该网站使用此处的 Nginx 构建包进行设置,https://github.com/heroku/heroku-buildpack-nginx,我不确定是否需要 Heroku 安装额外的设置 RTMP 服务器并侦听流的依赖项。
我想知道如何将我在创建的导航菜单中心编写的标题文本居中,文本已经居中,但它居中在导航菜单的顶部,而不是中间,这正是我所需要的。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home</title>
</head>
<style>
body {margin:0;}
.Header {
z-index: 100;
position: fixed;
top: 0;
left: 0;
width: 100%;
background-color: #000000;
height: 70px;
}
@media screen and (max-width:680px) {
.Header.responsive {position: relative;}
.Header.responsive li.icon {
position: absolute;
right: 0;
top: 0;
}
}
@media (max-width: 960px){
.Header .headerLogo{
display: inline-block;
width: 86px;
height: 15px;
margin-top: 17px;
margin-left: 6px;
}
}
</style>
</head>
<body>
<div class="Header" id="myHeader">
<a class = "headerLogo">
<header><center><i><font size = "6" …Run Code Online (Sandbox Code Playgroud) 我有两个电话到chrome.storage.local.get(). 在继续continueCode()为我的 chrome 扩展程序执行其余代码(调用函数)之前,我需要完成这些调用,但我不确定如何执行此操作,这是我的代码。
function getData() {
chrome.storage.local.get(['key'], function(result) {
if (Object.values(result)[0] != undefined) {
object1.innerHTML = Object.values(result)[0].val;
}
});
chrome.storage.local.get(['key2'], function(result) {
if (Object.values(result)[0] != undefined) {
object2.innerHTML = Object.values(result)[0].val;
}
});
continueCode();
}
Run Code Online (Sandbox Code Playgroud) 因此,我研究了我的网站的代码,当屏幕尺寸更改时,该代码将更改代码的某些部分的css甚至html。首先,我要寻找的是在Windows 10或Mac上将网站置于拆分屏幕时,我希望标题“ Some Title”移动到标题部分的左侧。我希望这将有助于我在屏幕尺寸更改时更改网站的某些方面。我的代码如下。
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>Some Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href= "Logo.png" type="img/SVG" style="width: 100%; height: 100%">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<link rel = "stylesheet" href="stylesheet.css">
</head>
<body>
<div class="Header" id="myHeader">
<a class = "headerLogo">
<a href="file:///C:/Noah's%20stuff/Home.html" ><h1 style="color:white; font-family: Verdana; font-style: italic; font-size: x-large;
text-align: center; padding-top: 20px">Some Title</h1></a>
<style>
a{text-decoration: none;}
a:hover{
text-decoration:none;
}
</style>
</a>
<div class="socialmedia">
<a class = "Facebook">
<a href="https://www.facebook.com/" target="_blank"><img src = "https://images.seeklogo.net/2016/09/facebook-icon-preview-1.png" width="50px" height="50px"></a> …Run Code Online (Sandbox Code Playgroud)当我部署到生产环境时,我尝试curl向 bitbucket 上的 CI/CD YAML 添加命令。该curl命令向 CloudFlare API 发送 POST 请求以清除缓存。该命令包含-H变量作为必要的 HTTP 标头。这导致 bitbucket 上出现缩进错误,因此我无法提交更改,而且我不确定原因。我不熟悉 YAML 语法以及如何解决此问题。
bitbucket-pipelines.YAML
image: python:3.7.4
clone:
depth: full
pipelines:
default:
- step:
caches:
- pip
script:
- echo "nothing"
branches:
prod:
- step:
name: Deploy to Staging
deployment: staging
script: #staging script
- git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_STAGING_APP_NAME.git HEAD:master --force
- step:
name: Deploy to Production
deployment: production
trigger: manual
script: #production script
- git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git HEAD:master --force
- "curl …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Python 设置 Google Drive API 实例来下载文件。我在 Google API 控制台上为特定项目设置了 OAuth 2.0 客户端 ID,并启用了 Google Drive API 客户端。但是,在本地主机上测试时,我不断收到redirect_uri_mismatch 错误。我在某处读到包含 http://localhost:8080 作为用于测试的重定向 URI,但是,redirect_uri_mismatch 错误不断在 localhost 上的随机端口上抛出错误。我不确定如何为本地主机设置正确的端口,因此不会不断抛出此错误。目前,该实例尝试使用的重定向 URI 是 http://localhost:49334/。如果我将该 URI 添加到我的credentials.json 文件中,那么它只会通过不同的端口抛出另一个不匹配错误。我该如何解决这个问题?我正是使用此文档中的代码:https://developers.google.com/drive/api/v3/quickstart/python和https://developers.google.com/drive/api/v3/manage-downloads。
flask ×4
python ×4
css ×2
heroku ×2
html ×2
asynchronous ×1
bitbucket ×1
center ×1
cloudflare ×1
connection ×1
deployment ×1
download ×1
flask-mail ×1
hashcode ×1
localhost ×1
nginx ×1
oauth-2.0 ×1
purge ×1
rtmp ×1
screen-size ×1
syntax-error ×1
task-queue ×1
unity-webgl ×1
worker ×1
yaml ×1