小编Mud*_*yla的帖子

将 current_user 从 Flask-Login 传递到 Plotly Dash 应用程序

我正在尝试构建一个集成在 Flask 应用程序中的 Dash 应用程序。一切似乎都工作正常,但当我尝试在 Dash 应用程序中显示登录用户时,它显示为“无”。

我的应用程序结构如下:

example/
example/
  dashapp/
    static/
      custom-css.css
    templates/
      base.html
      home.html
      login.html
    __init__.py
    app1.py
    forms.py
    models.py
    routes.py
  application.py
  config.py
  users.db
Run Code Online (Sandbox Code Playgroud)

我的 Dash 应用程序位于app1.py. 我尝试了多种方法来通过current_user但没有成功。不过结果很好home.html。我想问题是我的应用程序位于单独的文件中,而不是位于routes.py.

这是代码app.py

import dash
import dash_html_components as html
from dashapp import application
from flask_login import login_required, current_user


app1 = dash.Dash(__name__, server = application, routes_pathname_prefix = '/app1/', assets_folder = 'static', assets_url_path = '/static')
app1.scripts.config.serve_locally = True
app1.css.config.serve_locally = True

app1.layout = html.Div(
    children …
Run Code Online (Sandbox Code Playgroud)

python flask flask-login plotly-dash

6
推荐指数
1
解决办法
5441
查看次数

硒:访问被拒绝

我正在尝试使用 Selenium 从 LV 网站上抓取一些数据,并在单击“登录”按钮后不断收到“访问被拒绝”屏幕。我觉得有一种保护措施可以防止这种情况,因为当我手动执行相同操作时,一切似乎都工作正常。奇怪的是,我需要单击“登录”按钮两次才能手动登录。

我的代码:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=r'chromedriver.exe')
driver.get('https://secure.louisvuitton.com/eng-gb/mylv')
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//span[@class='ucm-wrapper']")))
driver.find_element_by_xpath("//button[@class='ucm-button ucm-button--default ucm-choice__yes']").click()
driver.find_element_by_id('loginloginForm').send_keys('xxx@xxx.com')
driver.find_element_by_id ('passwordloginForm').send_keys('xxxxxx')
driver.find_element_by_id('loginSubmit_').click()

Run Code Online (Sandbox Code Playgroud)

错误:

You don't have permission to access "http://secure.louisvuitton.com/eng-gb/mylv;jsessionid=xxxxxxx.front61-prd?" on this server.
Run Code Online (Sandbox Code Playgroud)

有没有办法用 Selenium 登录并绕过这个?

python selenium google-chrome selenium-chromedriver selenium-webdriver

5
推荐指数
2
解决办法
5510
查看次数

使用 cv2.pointPolygonTest() 和 cv2.polylines() 时出现问题

我正在尝试绘制一个形状,然后检查该点是否在形状内部。认为使用cv2.polylines()绘制它并cv2.pointPolygonTest()测试应该可以工作,但出现了一个信息量不大的错误。

Traceback (most recent call last):
  File "C:\Users\XXX\Desktop\Heatmap\cvtest.py", line 32, in <module>
    dist = cv2.pointPolygonTest(cv2.polylines(img,[pts],True,(0, 255 , 0), 2), (52,288), False)
cv2.error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\imgproc\src\geometry.cpp:103: error: (-215:Assertion failed) total >= 0 && (depth == CV_32S || depth == CV_32F) in function 'cv::pointPolygonTest'
Run Code Online (Sandbox Code Playgroud)

我猜用创建的形状cv2.polylines()不是轮廓。那么正确的做法是什么?我当前的代码:

import cv2
import numpy as np

img = cv2.imread('image.png')

pts = np.array([[18,306],[50,268],[79,294],[165,328],[253,294],[281,268],[313,306],[281,334],[270,341],[251,351],[230,360],[200,368],[165,371],[130,368],[100,360],[79,351],[50,334],[35,323]], np.int32)
pts = pts.reshape((-1,1,2))

dist = cv2.pointPolygonTest(cv2.polylines(img,[pts],True,(0, 255 , 0), 2), (52,288), False)
#print(dist)

cv2.imshow('test', img)
cv2.waitKey()
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)

python opencv

0
推荐指数
1
解决办法
1万
查看次数