小编Eri*_*ven的帖子

Python uvicorn:术语“uvicorn”不被识别为 cmdlet、函数、脚本文件的名称

晚上好,

\n

我正在使用 python 3.9 并尝试根据互联网上的文档在 Windows 10 Pro 上运行新的 FastAPI 服务https://www.uvicorn.org/我执行了以下语句

\n
pip install uvicorn pip install uvicorn[standard]\n
Run Code Online (Sandbox Code Playgroud)\n

创建示例文件 app.py

\n
from fastapi import FastAPI\n\napp = FastAPI()\n\n\n@app.get("/")\nasync def root():\n    return {"message": "Hello World"}\n
Run Code Online (Sandbox Code Playgroud)\n

但是当我运行下面的代码时:

\n
uvicorn main:app --reload\n\n\nuvicorn : The term \'uvicorn\' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify t\nhat the path is correct …
Run Code Online (Sandbox Code Playgroud)

python fastapi uvicorn

25
推荐指数
3
解决办法
6万
查看次数

from pymongo.objectid import ObjectId ImportError: No module named objectid

我制作了一个 Python 代码,用于从名为 Tweets 的 Mongo 集合中获取推文。我不想只获取对象文本并添加一个名为 Sentiment 的附加对象。

当我遍历推文并将 json 对象解析为字符串时,出现错误:

from pymongo.objectid import ObjectId ImportError: No module named objectid

因此我使用以下代码

import pymongo
import nltk
import json
from json import JSONEncoder
from pymongo import MongoClient
from pymongo.objectid import ObjectId

#JSON Encoder
class MongoEncoder(JSONEncoder):
    def default(self, obj, **kwargs):
        if isinstance(obj, ObjectId):
            return str(obj)
        else:            
            return JSONEncoder.default(obj, **kwargs)

#Mongo Settings
client = MongoClient()
db = client.Sentiment
Tweets = db.Tweet
TweetTraining = db.TweetTraining

#GET TEXT_TAG FROM TWEET
for tweet in Tweets.find({"lang":"nl"},{"text"}):
  print …
Run Code Online (Sandbox Code Playgroud)

python twitter mongodb pymongo

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

使用Tweepy获取推文时出错

我有一个Python脚本来获取推文.在脚本中我使用libary Tweepy.我使用有效的身份验证参数.运行此脚本后,一些推文存储在我的MongoDB中,有些推文被if语句拒绝.但我仍然得到错误

requests.packages.urllib3.exceptions.ProtocolError: ('Connection broken: IncompleteRead(0 bytes read, 2457 more expected)'
Run Code Online (Sandbox Code Playgroud)

我的问题是我可以改进脚本的哪一部分,所以我没有得到上面的错误.

这是我的剧本

    from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import time
import json
from pymongo import MongoClient

#Mongo Settings
client = MongoClient()
db = client.Sentiment
Tweets = db.Tweet

#Twitter Credentials
ckey ='myckey'
csecret ='mycsecret'
atoken = 'myatoken'
asecret = 'myasecret'

class listener(StreamListener):

    def on_data(self, data):
        try:  

            tweet = json.loads(data)

            if tweet["lang"] == "nl":
                print tweet["id"]
                Tweets.insert(tweet)



            return True
        except BaseException, e:
            print 'failed …
Run Code Online (Sandbox Code Playgroud)

python twitter mongodb tweepy

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

'app.router'已被弃用!在简单的网站上

我非常喜欢将NodeJS与Express结合使用.我正在尝试使用Bootstrap组件创建一个简单的网站.我用Express生成器生成了以下文件夹结构

  • app.js
  • bin(文件夹)
  • node_modules(文件夹)
  • 的package.json
  • public(文件夹:css,javascript,img)
  • 路线(index.js,oudRijswijk.js)
  • 视图(玉文件)

Express(版本4.13.1)NodeJS(版本0.10.25)

一切正常,直到我在app.js文件中添加一些额外的路由.

APP.JS

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var nodemailer = require('nodemailer');

var routes = require('./routes/index');
var oudRijswijk = require('./routes/oudRijswijk');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(app.router);
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser()); …
Run Code Online (Sandbox Code Playgroud)

javascript node.js express

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

npm安装fsevents错误

您好,我正在尝试安装fsevents whitch npm。因此,我使用以下版本:

  • 节点:4.2.6
  • NPM:3.5.2
  • 操作系统:Ubuntu 16.04 LTS

    我正在执行语句

已编辑

npm install fsevents --no-optional --save react-redux
Run Code Online (Sandbox Code Playgroud)

执行后,我在控制台中得到以下错误

已编辑

npm ERR! Linux 4.4.0-45-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "fsevents" "--no-
optional" "--save" "react-redux"
npm ERR! node v4.2.6
npm ERR! npm  v3.5.2
npm ERR! code EBADPLATFORM

npm ERR! notsup Not compatible with your operating system or  
architecture: fsevents@1.0.15
npm ERR! notsup Valid OS:    darwin
npm ERR! notsup Valid Arch:  any
npm ERR! notsup Actual OS:   linux
npm ERR! notsup Actual …
Run Code Online (Sandbox Code Playgroud)

node.js npm

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

reverse() 不是一个函数

我在 javascript 中编写了一个函数来计算我们的票务系统的库存。作为输入,我得到以下输入:

[{key:"10-09-2017", value:{countCreatedTickets: 98, countOpenTickets: 13, countSolvedTickets: 61}},
 {key:"12-09-2017", value:{countCreatedTickets:51,  countOpenTickets: 14, countSolvedTickets: 33}}
]
Run Code Online (Sandbox Code Playgroud)

我使用的函数是:

function funnelCalulation(ds){
    var stock = 0, stockCalulations = []
    console.info('-------  funnelCalulation -------')
    console.info(ds)
    ds = ds.reverse()

    for(var i = 0; i < ds.length; i++ ){
        if (i == 0){
            stock = ( ds[i].value.countCreatedTickets + ds[i].value.countOpenTickets ) - ds[i].value.countSolvedTickets
            stockCalulations.push({datum: ds[i].key, createdTickets: ds[i].value.countCreatedTickets, opentTickets: ds[i].value.countOpenTickets, ticketStock: stock })

        }
        if (i > 0){
            stock = ( ds[i].value.countCreatedTickets + ds[i].value.countOpenTickets + stock ) - …
Run Code Online (Sandbox Code Playgroud)

javascript arrays sorting

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

Python ModuleNotFoundError:没有名为“azure.cognitiveservices”的模块

我正在按照 Microsoft 的教程(https://learn.microsoft.com/nl-nl/azure/cognitive-services/Computer-vision/quickstarts-sdk/client-library?pivots=programming-language-python)来使用认知服务。我在这里使用 Visual Code 并使用命令行通过 pip 安装 Azure:

pip install azure-cognitiveservices-vision-customvision
Run Code Online (Sandbox Code Playgroud)

我使用第一个代码(参见下面的代码)并尝试运行代码。但它返回以下错误:

(myvenv) PS C:\Users\erikh\OneDrive\Documenten\Git\Python Testlab> & "c:/Users/erikh/OneDrive/Documenten/Git/Python Testlab/myvenv/Scripts/python.exe" "c:/Users/erikh/OneDrive/Documenten/Git/Python Testlab/readText.py"
Traceback (most recent call last):
  File "c:/Users/erikh/OneDrive/Documenten/Git/Python Testlab/readText.py", line 1, in <module>
    from azure.cognitiveservices.vision.computervision import ComputerVisionClient
ModuleNotFoundError: No module named 'azure.cognitiveservices'
Run Code Online (Sandbox Code Playgroud)

这是我尝试执行的代码:

from azure.cognitiveservices.vision.computervision import ComputerVisionClient
from azure.cognitiveservices.vision.computervision.models import OperationStatusCodes
from azure.cognitiveservices.vision.computervision.models import VisualFeatureTypes
from msrest.authentication import CognitiveServicesCredentials

from array import array
import os
from PIL import Image
import sys
import time

# Add your Computer …
Run Code Online (Sandbox Code Playgroud)

python azure python-3.x azure-cognitive-services

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

Docker 上的 Azure FileShare 返回无法应用新功能集

我正在使用 MySQL Docker 容器,我想在其中使用 Azure 文件共享。为了创建 MySQL Docker 容器,我使用以下构建脚本。

FROM mysql:5.7
RUN apt-get update && apt-get upgrade && apt-get install sudo
RUN sudo apt install cifs-utils -y
RUN sudo apt-get install curl -y
RUN cd home 
RUN mkdir install
RUN cd install
RUN curl curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
Run Code Online (Sandbox Code Playgroud)

当我进入此容器时,我使用从 Azure 门户中选择的以下命令并创建一个 bash 脚本。

在此输入图像描述

当我执行脚本时,我收到此错误:

无法应用新的功能集。

您能帮我将 Azure 文件共享安装到 Linux 吗?

非常感谢,

埃里克

azure-storage docker azure-files

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

Python AZ 翻译 由于凭据丢失或无效,请求未获授权

我正在使用 Python 3.8.3 并尝试使用 Azure Translation。基于( https://learn.microsoft.com/nl-nl/azure/cognitive-services/Translator/quickstart-translate?pivots=programming-language-python )的示例,我尝试为自己重新创建示例并最小化代码。

在此输入图像描述

我创建一个 Azure 资源(翻译)并复制代码中的密钥端点。但是当我运行代码时,出现以下错误:

“code”:401000,
“message”:“由于凭据丢失或无效,请求未获授权。”

有人可以解释一下我做错了什么以及如何解决这个问题!

我使用这段代码:

import os, requests, uuid, json

path = '/translate?api-version=3.0'
params = '&to=de&to=it'
constructed_url = "https://api.cognitive.microsofttranslator.com" + path + params

headers = {
    'Ocp-Apim-Subscription-Key': 'xxxxxxxxxxxx',
    'Content-type': 'application/json',
    'X-ClientTraceId': str(uuid.uuid4())
}

# You can pass more than one object in body.
body = [{
    'text' : 'Hello World!'
}]
request = requests.post(constructed_url, headers=headers, json=body)
response = request.json()

print(json.dumps(response, sort_keys=True, indent=4, separators=(',', ': '))) …
Run Code Online (Sandbox Code Playgroud)

python python-3.x azure-cognitive-services

3
推荐指数
1
解决办法
1360
查看次数

Mongo DB $和两个字段的条件

我在MongoDb Tweet Training中有一个集合,在这些集合中,我收集了有关tweet的特定信息。我有三个领域(情感,类别和tekst)。我将不执行查询来识别“类别”等于“荷兰合作银行”且情绪等于“中性”或“类别”等于“ Ing”且情绪等于“中性”。

我之前使用以下查询:

db.TweetTraining.find( { 
    $and: [ 
            { $or: [ { sentiment:"neutraal" } ,{ Categorie:"Rabobank" } ]},
            { $or: [ { sentiment:"neutraal" } ,{ Categorie:"Ing" } ]}
]})
Run Code Online (Sandbox Code Playgroud)

但是除了获得正确的结果外,我还会得到其他Cattegorie的结果。

mongodb mongodb-query

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