小编dat*_*den的帖子

找不到 Docker Debian nc 命令

当我Debian从 docker-compose构建我的图像时,使用命令$ docker-compose -f docker-compose-dev.yml build web,如下所示:

docker-compose-fev.yml

services:

  web:
    build:
      context: ./services/web
      dockerfile: Dockerfile-dev
    volumes:
      - './services/web:/usr/src/app'  
    ports:
      - 5001:5000
    environment:
      - FLASK_ENV=development
      - APP_SETTINGS=project.config.DevelopmentConfig
      - DATABASE_URL=postgres://postgres:postgres@web-db:5432/web_dev 
      - DATABASE_TEST_URL=postgres://postgres:postgres@web-db:5432/web_test
      - SECRET_KEY=my_precious
    depends_on:  
      - web-db
      - redis
Run Code Online (Sandbox Code Playgroud)

好像它似乎成功构建了所有包,我得到:

web_1| /usr/src/app/entrypoint.sh: 5: /usr/src/app/entrypoint.sh: nc: not found
Run Code Online (Sandbox Code Playgroud)

如果我更改#!/bin/sh#!/bin/bash,则错误日志更改:

web_1| /usr/src/app/entrypoint.sh: line 5: nc: command not found
Run Code Online (Sandbox Code Playgroud)

Dockerfile:

FROM python:3.7-slim-buster

RUN apt-get update && apt-get -y dist-upgrade
RUN apt-get -y install build-essential libssl-dev libffi-dev libblas3 …
Run Code Online (Sandbox Code Playgroud)

docker docker-entrypoint

8
推荐指数
1
解决办法
8202
查看次数

Python - 在本地函数调用中解压缩kwargs

我想传递一个dictionary:

items = {"artist": "Radiohead", "track": "Karma Police"}
Run Code Online (Sandbox Code Playgroud)

作为参数function:

def lastfm_similar_tracks(**kwargs):

    result = last.get_track(kwargs)
    st = dict(str(item[0]).split(" - ") for item in result.get_similar())
    print (st)
Run Code Online (Sandbox Code Playgroud)

last.get_track("Radiohead", "Karma Police")调用本地的正确方法在哪里function.

然后像这样调用它:

lastfm_similar_tracks(items)
Run Code Online (Sandbox Code Playgroud)

我收到这个错误:

TypeError: lastfm_similar_tracks() takes exactly 0 arguments (1 given)

我该怎么纠正这个?

python kwargs

7
推荐指数
3
解决办法
8065
查看次数

在Docker中使用React和Nginx授权Spotify

我正在构建REST API具有以下结构的dockerized 应用程序:

../
  web/
  nginx/
       dev.conf   
       Dockerfile-dev  
  client/
        build/
        conf/
        Dockerfile-dev
        node_modules/
        package_json
        public/
        src/
           App.jsx   
           components/ 
                     SpotifyRedirect.jsx                  
 spotify-client/ 
                Dockerfile-dev
                node_modules
                package-lock.json
                package.json
                authorization_code/
                                  app.js 
Run Code Online (Sandbox Code Playgroud)

注意:在此项目中,用户需要经历两个授权/认证过程:

  1. 一个与我的应用程序一起生成的本地应用程序token(已经处理过)
  2. 另一个带有Spotify(需要一个,redirect URI并为其提供自己token的API访问权限)

    2a)因此,在()localhost之后localhost/auth/registerlocalhost/auth/login提交时,我会有Spotify redirect URIhttp://localhost:8888)带我到此页面:

在此处输入图片说明

2b)然后,单击登录按钮,将要求我将我的应用程序与Spotify连接,如下所示:

在此处输入图片说明

最后OK,我将被授予权限并交给token我,我可以保存甚至刷新给我的React客户。


该项目的构建基块是从本教程中提取的:

使用-spotifys真棒api与反应

但是,我已经配置了React client,除了此授权过程之外,它还可以用于其他目的。

以下是尝试将这两个服务集成在一起的相关代码:更通用的clientspotify-client


相关代码:

因此,我的第一个尝试是为spotify-client下方的client …

nginx spotify npm docker reactjs

7
推荐指数
1
解决办法
248
查看次数

Flask 和 React - 在 Spotify 授权后处理令牌

我已经在我的应用程序中实现了用于用户登录的 JWT(在 Spotify Auth 之前),如下所示:

烧瓶

@auth_blueprint.route('/auth/login', methods=['POST'])
def login_user():
    # get post data
    post_data = request.get_json()
    response_object = {
        'status': 'fail',
        'message': 'Invalid payload.'
    }
    if not post_data:
        return jsonify(response_object), 400
    email = post_data.get('email')
    password = post_data.get('password')
    try:
        # fetch the user data
        user = User.query.filter_by(email=email).first()
        if user and bcrypt.check_password_hash(user.password, password):
            auth_token = user.encode_auth_token(user.id)
            if auth_token:
                response_object['status'] = 'success'
                response_object['message'] = 'Successfully logged in.'
                response_object['auth_token'] = auth_token.decode()
                return jsonify(response_object), 200
        else:
            response_object['message'] = 'User does not exist.'
            return jsonify(response_object), …
Run Code Online (Sandbox Code Playgroud)

authentication authorization flask jwt reactjs

7
推荐指数
1
解决办法
1135
查看次数

值错误 X 有 24 个特征,但 DecisionTreeClassifier 期望有 19 个特征作为输入

我正在尝试在我的机器上使用拓扑数据分析 (TDA)重现这个GitHub 项目。

我的步骤

  • 从交叉验证输出中获取最佳参数
  • 加载我的数据集特征选择
  • 从数据集中提取拓扑特征进行预测
  • 创建一个基于最佳参数的随机森林分类器模型
  • 计算测试数据的概率

背景

  1. 特征选择

为了决定哪些属性属于哪个组,我们创建了一个相关矩阵。由此,我们看到有两个大的群体,其中玩家属性相互之间具有很强的相关性。因此,我们决定将属性分为两组,一组概括球员的进攻特点,另一组概括防守。最后,由于守门员与其他球员的统计数据完全不同,我们决定只考虑整体评分。下面,可以看到24 个功能每个播放器使用:

进攻:“定位”、“传中”、“终结”、“heading_accuracy”、“short_passing”、“反应”、“截击”、“盘带”、“曲线”、“free_kick_accuracy”、“加速度”、“冲刺速度”、 “敏捷”、“罚球”、“视野”、“射门力量”、“远射” 防守:“拦截”、“侵略”、“盯人”、“站立铲球”、“滑动铲球”、“远距离传球” 守门员:“整体评分”

根据这组特征,我们下一步要做的是,对于每个非守门员球员,计算攻击属性和防守属性的平均值。

最后,对于给定比赛中的每支球队,我们根据球队球员的这些统计数据计算进攻和防守的平均值和标准差,以及最佳进攻和最佳防守。

以这种方式,一场比赛由 14 个特征(GK 总分、最佳进攻、标准进攻、平均进攻、最佳防守、标准防守、平均防守)来描述,这些特征将比赛映射到空间中,遵循两队的特点.


  1. 特征提取

TDA 的目的是捕捉数据底层空间的结构。在我们的项目中,我们假设数据点的邻域隐藏了与比赛结果相关的有意义的信息。因此,我们探索了寻找这种相关性的数据空间。


方法

def get_best_params():
    cv_output = read_pickle('cv_output.pickle')
    best_model_params, top_feat_params, top_model_feat_params, *_ = cv_output

    return top_feat_params, top_model_feat_params

def load_dataset():
    x_y = get_dataset(42188).get_data(dataset_format='array')[0]
    x_train_with_topo = x_y[:, :-1]
    y_train = x_y[:, -1]

    return x_train_with_topo, y_train


def extract_x_test_features(x_train, y_train, players_df, pipeline):
    """Extract the topological features from the test set. This requires also …
Run Code Online (Sandbox Code Playgroud)

python decision-tree topological-sort cross-validation

7
推荐指数
1
解决办法
980
查看次数

Flask - 作业不作为后台进程运行

我正在尝试运行一个Flask包含以下内容的应用:

  1. 即时生成API请求
  2. 将每个请求上载到SQLalchemy数据库
  3. 运行作业12作为后台进程

为此,我有以下代码:

from flask import Flask
from flask import current_app
import concurrent.futures
from concurrent.futures import ThreadPoolExecutor
import queue

app = Flask(__name__)
q = queue.Queue()

def build_cache(): 
    # 1. Yielding API requests on the fly
    track_and_features = spotify.query_tracks() # <- a generator
    while True:
        q.put(next(track_and_features))


def upload_cache(tracks_and_features):
    # 2. Uploading each request to a `SQLalchemy` database
    with app.app_context():      
        Upload_Tracks(filtered_dataset=track_and_features)

    return "UPLOADING TRACKS TO DATABASE" 


@app.route('/cache')
def cache():
    # 3. Do …
Run Code Online (Sandbox Code Playgroud)

python flask flask-sqlalchemy concurrent.futures

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

Docker-Celery 无法连接到 redis

项目结构:

client
nginx
web/
   celery_worker.py
   project
   config.py
   api/
Run Code Online (Sandbox Code Playgroud)

我的 docker-compose 中有以下服务:

version: '3.6'

services:

  web:
    build:
      context: ./services/web
      dockerfile: Dockerfile-dev
    volumes:
      - './services/web:/usr/src/app'
    ports:
      - 5001:5000
    environment:
      - FLASK_ENV=development
      - APP_SETTINGS=project.config.DevelopmentConfig
      - DATABASE_URL=postgres://postgres:postgres@web-db:5432/web_dev 
      - DATABASE_TEST_URL=postgres://postgres:postgres@web-db:5432/web_test
      - SECRET_KEY=my_precious  
    depends_on:  
      - web-db
      - redis

  celery:
    image: dev3_web
    restart: always
    volumes:
      - ./services/web:/usr/src/app
      - ./services/web/logs:/usr/src/app
    command: celery worker -A celery_worker.celery --loglevel=INFO -Q cache
    environment:
      - CELERY_BROKER=redis://redis:6379/0
      - CELERY_RESULT_BACKEND=redis://redis:6379/0
    depends_on:
      - web
      - redis
    links:
      - redis:redis


  redis:
    image: redis:5.0.3-alpine
    restart: always
    expose:
      - …
Run Code Online (Sandbox Code Playgroud)

redis celery docker docker-compose

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

React - TypeError:无法读取未定义的属性“包含”

我是 React 的新手,抱歉,如果这太基本了。

我有一个输入表单,我正在尝试处理对它的提交和更改,如下所示:

import { editMenuFormRules } from './forms/form-rules.js';

class Seeds extends Component{
  constructor (props) {
    super(props);
    this.state = { 
        formData: {
          coffee:''
        },
        menu:[],
        editMenuFormRules:editMenuFormRules,

    };
    this.handleSubmitCoffees = this.handleSubmitCoffees.bind(this);
    this.handleBeanFormChange = this.handleBeanFormChange.bind(this);
  };

componentDidMount() {
    if (this.props.isAuthenticated) {
      this.getSeeds();
    }
  };

getSeeds(event) {
    const {userId} = this.props
    const options = {
      url: `${process.env.REACT_APP_WEB_SERVICE_URL}/seeds/${userId}`,
      method: 'get',
      headers: {
        'Content-Type': 'application/json',
         Authorization: `Bearer ${window.localStorage.authToken}`
      }
    };
    return axios(options)
    .then((res) => {
      console.log(res.data.data)
      this.setState({
        menu: res.data.data[0].menu
      })
    })    
    .catch((error) => { …
Run Code Online (Sandbox Code Playgroud)

reactjs

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

Flask - 无法获取 cookie

我有以下端点开始授权流程:

@spotify_auth_bp.route("/index", methods=['GET', 'POST'])
def spotify_index():
    CODE = "code"
    CLIENT_ID =   os.environ.get('SPOTIPY_CLIENT_ID')
    SCOPE = os.environ.get('SPOTIPY_SCOPE')
    REDIRECT_URI = os.environ.get('SPOTIPY_REDIRECT_URI')

    SPOTIFY_AUTH_URL = "https://accounts.spotify.com/authorize"

    return redirect("{}?response_type={}&client_id={}&scope={}&redirect_uri={}".format(
        SPOTIFY_AUTH_URL, CODE, CLIENT_ID, SCOPE, REDIRECT_URI), code=302)
Run Code Online (Sandbox Code Playgroud)

然后我从 Spotify 重定向回/callback,我jwt在响应中设置cookie,如下所示:

 @spotify_auth_bp.route("/callback", methods=['GET', 'POST'])
 def spotify_callback():
    token = user.encode_access_token(access_token)
    a11n_h, a11n_d, a11n_s = token.decode().split('.')
    response = make_response(redirect('http://localhost/about', code=302))
    response.set_cookie('a11n.h', a11n_h)
    response.set_cookie('a11n.d', a11n_d) 
    response.set_cookie('a11n.s', a11n_s, httponly=True)  

    return response
Run Code Online (Sandbox Code Playgroud)

cookie 显示在我的浏览器控制台中的“应用程序”下。


现在我想从另一个端点获取它们,如下所示:

@spotify_auth_bp.route("/get_token/<user_id>", methods=['GET', 'POST'])
def get_token(user_id):
    # get access token cookies
    a11n_h = request.cookies.get('a11n.h')
    a11n_d = …
Run Code Online (Sandbox Code Playgroud)

python cookies flask jwt

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

TypeError:对象不可JSON序列化

我对以下错误感到好奇:

TypeError: Object of type 'Menu' is not JSON serializable
Run Code Online (Sandbox Code Playgroud)

毕竟,当我转到端点时'/users',数据已经序列化了

menu: [
   {
    id: 1,
    created: "2019-06-24T22:24:50.811520",
    items: [
        {
         id: 1,
         name: "pasta",
         created: "2019-06-24T22:24:50.850468"
         },
        {
         id: 2,
         name: "burger",
         created: "2019-06-24T22:25:25.828976"
        }
      ]
    }
Run Code Online (Sandbox Code Playgroud)

但是当我转到route时,应用程序视图因上面的序列化错误而中断'/edit_menu'。下面我显示相关代码:


表格:

1)用户(正在序列化)

class User(db.Model):   
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    restaurant = db.Column(db.String(128))

    menu = db.relationship("Menu",
                    backref=db.backref('user'), 
                    uselist=True)

    def __init__(self, restaurant):
        self.restaurant = restaurant
        self.username = username

    def serialize(self):
       return { 
        'id': self.id, …
Run Code Online (Sandbox Code Playgroud)

serialization json flask-sqlalchemy

5
推荐指数
1
解决办法
975
查看次数