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" }, becauseimport requestswas 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 requestswas 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)