Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Heroku上的烧瓶API-<;答复[503]>;-JSONDecodeError:应为值:第1行第1列(字符0)_Python - Fatal编程技术网

Python Heroku上的烧瓶API-<;答复[503]>;-JSONDecodeError:应为值:第1行第1列(字符0)

Python Heroku上的烧瓶API-<;答复[503]>;-JSONDecodeError:应为值:第1行第1列(字符0),python,Python,我正在尝试在Heorku上部署我的flask应用程序。该应用程序在我的本地系统上运行良好,但当我在Heroku上部署该应用程序并进行测试时,它会给我一个响应。 附上下面的代码 import requests import json import time url = 'https://ner-spacy-2.herokuapp.com/' text = 'MUMBAI: Office-based employees Hindustan Unilever ( HUL ) went work-fr

我正在尝试在Heorku上部署我的flask应用程序。该应用程序在我的本地系统上运行良好,但当我在Heroku上部署该应用程序并进行测试时,它会给我一个响应。 附上下面的代码

import requests
import json
import time
url = 'https://ner-spacy-2.herokuapp.com/'

text = 'MUMBAI: Office-based employees Hindustan Unilever ( HUL ) went work-from-home (WFH) mode March 17 itself, Rs 38,000-crore    FMCG    major framed new set protocols employees, area sales managers (ASMs) field force.   incident management team (IMT) — cross-functional steering committee — set lead multiple pillars Covid-19 readiness, 1,000 circle meetings (virtual meetings manager team) taken place cover'

data = json.dumps(text)
send_request = requests.post(url, data)

这是回复:503

我的建筑在heroku很成功。在下面找到flask应用程序代码

import pandas as pd
from flask import Flask, jsonify, request
import pickle

import en_core_web_md
nlp = en_core_web_md.load()

# app
app = Flask(__name__)
@app.route('/', methods=['POST'])
def get_ner_tags():
    try:
        data = request.get_json(force=True)
        valid_labels = ['PERSON','NORP','FAC','ORG','LOC','PRODUCT','EVENT','WORK_OF_ART','LAW','LANGUAGE']
        geo_label = ['GPE']
        cardinality_labels = ['PERCENT','MONEY','QUANTITY']
        
        article_tags = []
        geo_tags = []
        cardinal_tags = []

        doc = nlp(data)

        for X in doc.ents:
          if X.label_ in valid_labels:
            article_tags.append(X.text)
          elif X.label_ in geo_label:
            geo_tags.append(X.text)
          elif X.label_ in cardinality_labels:
            cardinal_tags.append(X.text)

        article_tags = list(dict.fromkeys(article_tags))
        geo_tags = list(dict.fromkeys(geo_tags))
        cardinal_tags = list(dict.fromkeys(cardinal_tags))

        try:
        # fuzzy matching to remove duplicates
          article_tags = list(process.dedupe(article_tags, threshold=80, scorer=fuzz.token_set_ratio))
        except:
          article_tags = article_tags

        output = {'tags': [article_tags, geo_tags, cardinal_tags]}
        # return jsonify(results=output)
        return jsonify(results=output)
    
   except Exception as e:
        return jsonify(results=e)

app.run()



在请求中,只发送文本而不是JSON

import requests
import json
import time
url = 'https://ner-spacy-2.herokuapp.com/'

text = {'MUMBAI': 'Office-based employees Hindustan Unilever ( HUL ) went work-from-home (WFH) mode March 17 itself, Rs 38,000-crore    FMCG    major framed new set protocols employees, area sales managers (ASMs) field force.   incident management team (IMT) — cross-functional steering committee — set lead multiple pillars Covid-19 readiness, 1,000 circle meetings (virtual meetings manager team) taken place cover'}

send_request = requests.post(url, json=text)```

您的描述不完整您发送了
数据
,但变量
文本中的数据
或有错误对不起,我忘记添加一行,现在添加了一行,但错误是same@VishalSingh这是一样的。。。我忘了在我在Stackover flow上发布的问题中添加这一行,但将其包含在原始代码中。谢谢您的代码不正确:因为如果您只执行
data=json,您应该将
text
转换为
dict
。转储(文本)
它将只是文本
打印(类型(数据))