小编SVi*_*ill的帖子

Python:如何在烧瓶中显示matplotlib

我对Flask和Matplotlib很新.我希望能够显示我在某些HTML中生成的简单图表,但我很难搞清楚如何.这是我的Python代码:

from flask import Flask, render_template
import numpy as np
import pandas
import matplotlib.pyplot as plt

app = Flask(__name__)
variables = pandas.read_csv('C:\\path\\to\\variable.csv')
price =variables['price']


@app.route('/test')
def chartTest():
    lnprice=np.log(price)
    plt.plot(lnprice)
    return render_template('untitled1.html', name = plt.show())

if __name__ == '__main__':
   app.run(debug = True)
Run Code Online (Sandbox Code Playgroud)

这是我的HTML:

<!doctype html>
<html>
   <body>

      <h1>Price Chart</h1>

      <p>{{ name }}</p>

      <img src={{ name }} alt="Chart" height="42" width="42">

   </body>
</html>
Run Code Online (Sandbox Code Playgroud)

python matplotlib flask

11
推荐指数
2
解决办法
2万
查看次数

无法在 VSCode 中设置 C++ 调试;无法识别调试类型

我正在尝试设置 VSCode 来开始学习 C++。作为其中的一部分,我需要能够调试代码,因此我使用 .vsix 文件安装了 C/C++ 扩展,以允许它添加 C++ 调试配置。但是,当我尝试设置配置时,我没有将 C++ 视为环境选项;仅节点、gdb 和 lldb。按照此处的说明,我在命令选项板中没有看到任何有关 C++ 的建议。因此,我手动设置任务、c_cpp_properties 和 launch.json 文件,复制、粘贴并根据需要修改路径。但是,VSCode 将 launch.json 中的 cppdbg 标记为未识别为调试类型,并将 stopAtEntry、environments、MIMode 和 miDebuggerPath 字段标记为“Property <...> not allowed”。如果我将其更改为 gdb,它会识别调试类型,但属性不允许错误仍然存​​在:

c_cpp_properties.json:

{
  "configurations": [
    {
      "name": "Win32",
      "includePath": ["${workspaceFolder}/**", "${vcpkgRoot}/x86-windows/include"],
      "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
      "windowsSdkVersion": "10.0.17763.0",
      "compilerPath": "C:\\dev\\tools\\mingw64\\bin\\g++.exe",
      "cStandard": "c11",
      "cppStandard": "c++17",
      "intelliSenseMode": "${default}"
    }
  ],
  "version": 4
}
Run Code Online (Sandbox Code Playgroud)

任务.json:

{
    "version": "2.0.0",
    "tasks": [
      {
        "label": "build hello world",
        "type": "shell",
        "command": "g++",
        "args": ["test.cpp"], …
Run Code Online (Sandbox Code Playgroud)

c++ debugging installation mingw-w64 visual-studio-code

8
推荐指数
2
解决办法
2万
查看次数

无法启动 haproxy 2.4 - 最后一行缺少 LF?

基本上就是标题。我正在努力将现有的 haproxy 从 1.5 升级到最新版本。因此,我正在设置一个测试用例,以确保我们的旧设置可以正常工作。但是,当我尝试运行它时,出现以下错误:

[NOTICE]   (28948) : haproxy version is 2.4.1-1ce7d49
[NOTICE]   (28948) : path to executable is /home/user/test/usr/local/sbin/haproxy
[ALERT]    (28948) : parsing [test.cfg:22]: Missing LF on last line, file might have been truncated at position 68.
[ALERT]    (28948) : Error(s) found in configuration file : test.cfg
[ALERT]    (28948) : Fatal errors found in configuration.
Run Code Online (Sandbox Code Playgroud)

我尝试查找它,但找不到任何有关错误的信息。我已经检查过我的配置文件,它使用的是正确的 Unix 格式。另外,我的测试配置适用于旧版本的 HAProxy。

global
   stats timeout 30s
   user root
   group root

defaults
   log global
   mode http
   option httplog
   option dontlognull
   timeout connect 5000 …
Run Code Online (Sandbox Code Playgroud)

installation configuration makefile haproxy

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

试图欺骗电子邮件地址

我确信这已被问到,但我找不到任何让我的工作.

我正在尝试向客户发送跟进电子邮件,但我想欺骗电子邮件地址,因此来自我的同事的地址.我在网上看到,标题中的起始地址只是一个可以编辑的文本字段,但我仍然无法发送电子邮件.

import smtplib

email_to = '*****@gmail.com'
username = '*******@outlook.com'
password = '*********'
other_email = '*******@outlook.com'

mail = smtplib.SMTP('Outlook.com', 25)
mail.ehlo()
mail.starttls()
mail.login(username,password)

header = ('To:' + email_to + '\n' +'From: ' + other_email + '\n'
          + 'Subject: Python Project Test\n')
message = (header +
           '\n\n This is a test message generated from a Python script. \n\n')

mail.sendmail(username, email_to, message)
mail.close()
print("Email sent successfully.")
Run Code Online (Sandbox Code Playgroud)

我知道这可以做到,但是有人能指出我正确的方向吗?有没有什么方法可以让我在from字段中将我的名字伪装成应该得到这个的电子邮件?

===================================

另外,为了完成,这是我得到的错误:

Traceback (most recent call last):
  File "C:\Users\*****\Desktop\email outlook.py", line 16, in <module>
    mail.sendmail(username, …
Run Code Online (Sandbox Code Playgroud)

python email

2
推荐指数
1
解决办法
2880
查看次数

Guava Cache:如何处理空值

我已经构建了一个缓存,当您输入参数时,该缓存以列表格式返回一个值。如果该值不在缓存中,它将转到数据库并检索它,将其放入缓存中以备将来参考:

private ProfileDAO profileDAO;
private String[] temp;
    private LoadingCache<String, List<Profile>> loadingCache = CacheBuilder.newBuilder()
            .refreshAfterWrite(5, TimeUnit.MINUTES)
            .expireAfterWrite(5, TimeUnit.MINUTES)
            .build(
                    new CacheLoader<String, List<Profile>>() {
                        @Override
                        public List<Profile> load(String key) throws Exception {
                            logger.info("Running method to retrieve from database");
                            temp = key.split("\\|");
                            String instance = temp[0];
                            String name = temp[1];
List<Profile> profiles= profileDAO.getProfileByFields(id, name);
                            if (profiles.isEmpty()) {
                                List<Profile> nullValue = new ArrayList<Profile>();
                                logger.info("Unable to find a value.");
                                return nullValue;
                            }
                            logger.info("Found a value");
                            return profileDAO.getProfileByFields(id, name);
                        }
                    }
            );

public List<Profile> getProfileByFields(String id, …
Run Code Online (Sandbox Code Playgroud)

java null return-value guava

2
推荐指数
3
解决办法
4719
查看次数

删除或自动输入 haproxy ssl 的 pem 密码;Chrome 仍会警告 CA 未签名

我最近收到了一个用于 haproxy SSL 终止的签名证书。为了让 haproxy 使用它,我需要将 jks 文件转换为 pem 文件。首先,我将收到的 cer 文件转换为 crt,因为我之前遇到过错误,haproxy 无法在 pem 文件中找到 crt 文件。对所有证书执行此操作:

$ openssl x509 -inform PEM -in <CER file here> -out <CRT output file>
Run Code Online (Sandbox Code Playgroud)

然后我将根证书、中间证书和服务证书导入到已经拥有私钥的密钥库:

keytool -importcert -file $CERT -alias $ALIAS -keystore test.jdk
Run Code Online (Sandbox Code Playgroud)

然后我将 jsk 文件转换为 p12 文件,然后将其转换为 pem 文件:

$ keytool -importkeystore -srckeystore test.jks -destkeystore test.p12 -srcstoretype jks -deststoretype pkcs12
Enter destination keystore password:
Re-enter new password:


$ openssl pkcs12 -in test.p12 -out test.pem
Enter Import Password:
MAC verified OK
Enter PEM …
Run Code Online (Sandbox Code Playgroud)

ssl openssl certificate haproxy keytool

2
推荐指数
1
解决办法
3583
查看次数

Java:使用不带行号的 InputStream 和 Apache Commons CSV

这可能非常简单,但我还没有找到执行此操作的选项。我正在尝试使用 Apache Commons CSV 读取文件以供以后验证。有问题的 CSV 作为输入流提交,它似乎在读取文件时向文件添加了一个附加列,其中包含行号。如果可能的话,我希望能够忽略它,因为标题行不包含数字,这会导致错误。InputStream 中是否已有选项可以执行此操作,或者我必须设置某种后处理?

我使用的代码如下:

public String validateFile(InputStream filePath) throws Exception{
        System.out.println("Sending file to reader");
        System.out.println(filePath);
        InputStreamReader in = new InputStreamReader(filePath);
        //CSVFormat parse needs a reader object
        System.out.println("sending reader to CSV parse");
        for (CSVRecord record : CSVFormat.DEFAULT.withHeader().parse(in)) {
            for (String field : record) {
                System.out.print("\"" + field + "\", ");
            }
            System.out.println();
        }
        return null;
    }
Run Code Online (Sandbox Code Playgroud)

使用时withHeader(),我最终出现以下错误:

java.lang.IllegalArgumentException: A header name is missing in [, Employee_ID, Department, Email]
Run Code Online (Sandbox Code Playgroud)

我不能简单地跳过它,因为我需要对标题行进行一些验证。

另外,这里还有一个 CSV 文件示例:

"Employee_ID", "Department", …
Run Code Online (Sandbox Code Playgroud)

java csv inputstream apache-commons-csv

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