烧瓶:当我导入请求时,为什么我的服务器停滞不前?

发布于 2025-02-13 03:30:20 字数 1488 浏览 0 评论 0原文

方案

我正在使用python烧结服务器从远程数据库中提供数据。我很想使用请求框架与持有连接连接到我的数据库。

使用的技术

  • python 3.10
  • 烧瓶 2.0.3
  • 诗歌 1.0(对于依赖项)
  • 请求 2.28.1(添加诗歌)
  • IBM代码引擎(云平台/环境)

exudy

我的项目正常工作,直到我添加行import import import请求在我的server.py.py的顶部。当我添加此行时,我的服务器没有给出任何响应,并且会出来。

代码

以下输出{“ Hello”:“ WHINE”},因为import requests未添加。

import os
import sys
import json
from collections import Counter
from flask import Flask, render_template, request, session, url_for, jsonify

app = Flask(__name__)

@app.route('/', methods=['POST', 'GET'])
def main():
    return { 'hello': "there" }

if __name__ == 'main':
    app.run()

以下失速和服务器没有响应,因为导入请求 已添加

import os
import sys
import json
import requests # adding this
from collections import Counter
from flask import Flask, render_template, request, session, url_for, jsonify

app = Flask(__name__)

@app.route('/', methods=['POST', 'GET'])
def main():
    return { 'hello': "there" }

if __name__ == 'main':
    app.run()

问题

为什么我不能导入请求,如果我缺少某些内容,请您留下有关我需要做什么以使此工作的答案?

(我注意到其他一些框架也不能导入)

SCENARIO

I am using a python flask server to serve up data from my remote database. I am tempting to use the requests framework to connect to my database with a held connection.

TECHNOLOGY USED

  • Python 3.10
  • Flask 2.0.3
  • Poetry 1.0 (for dependencies)
  • Requests 2.28.1 (added with Poetry)
  • IBM Code Engine (cloud platform/environment)

ISSUE

My project works just fine up until I add the line import request at the top of my server.py. When I add this line no responses are given by my server and it times out.

CODE

The below outputs { "hello": "there" }, because import requests was not added.

import os
import sys
import json
from collections import Counter
from flask import Flask, render_template, request, session, url_for, jsonify

app = Flask(__name__)

@app.route('/', methods=['POST', 'GET'])
def main():
    return { 'hello': "there" }

if __name__ == 'main':
    app.run()

The below stalls and servers no response, because import requests was added.

import os
import sys
import json
import requests # adding this
from collections import Counter
from flask import Flask, render_template, request, session, url_for, jsonify

app = Flask(__name__)

@app.route('/', methods=['POST', 'GET'])
def main():
    return { 'hello': "there" }

if __name__ == 'main':
    app.run()

QUESTION

Why can't I import requests, and if I'm missing something could you please leave a code answer as to what I need to do to get this working?

(I've noticed some other frameworks can't be imported either)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文