I’ve been using AWS CodePipeline to execute a CI/CD pipeline. The ‘build’ stage performs correctly, which uses both the ‘Dockerfile’ and ‘requirements.txt’ files, whereas the ‘deploy stage’ utilizes Python files. Upon attempting, I encounter this error:
Traceback (most recent call last):
File "/MythicalMysfitsService/mythicalMysfitsService.py", line 3, in <module>
from urllib3.packages import six
**ModuleNotFoundError: No module named 'urllib3.packages'**
But the strange thing is that I already have ‘urllib3’ installed, based on modifying my Dockerfile:
FROM ubuntu:latest
ENV PIP_BREAK_SYSTEM_PACKAGES 1
# Update and install required packages
RUN echo Updating existing packages, installing and upgrading python and pip.
RUN apt-get update -y && apt-get install python3 -y
RUN apt-get install -y python3-pip python3-dev build-essential
RUN pip3 install --upgrade flask
RUN pip3 install -U flask-cors
RUN echo Copying the Mythical Mysfits Flask service into a service directory.
# Copy application files
COPY ./service /MythicalMysfitsService
# Set working directory
WORKDIR /MythicalMysfitsService
RUN echo Installing Python packages listed in requirements.txt
# Install Python dependencies
RUN pip3 install boto3
RUN pip3 install -r ./requirements.txt
RUN pip3 uninstall urllib3
RUN pip3 install --no-cache-dir -U urllib3
RUN python3 -m pip install --upgrade urllib3
RUN echo Starting python and starting the Flask service...
ENTRYPOINT ["python3"]
CMD ["mythicalMysfitsService.py"]
As well as my ‘requirements.txt.’ file:
boto3>=1.11.16
Werkzeug==2.3.0
Flask==2.3.0
Flask-Bcrypt==1.0.1
Flask-Login==0.6.2
Flask-SQLAlchemy==3.1.1
Flask-WTF==1.2.
flask-cors==4.0.
requests
six
urllib3
I also have modified my ‘mythicalMysFitsService.py’ Python file to try importing urllib3
:
from flask import Flask, jsonify, json, Response, request
from flask_cors import CORS
from urllib3.packages import six
from .packages.six import HTTPConnection as _HTTPConnection
from .packages.six import HTTPException
import mysfitsTableClient
# A very basic API created using Flask that has two possible routes for requests.
app = Flask(__name__)
CORS(app)
# The service basepath has a short response just to ensure that healthchecks
# sent to the service root will receive a healthy response.
@app.route("/")
def healthCheckResponse():
return jsonify({"message" : "Nothing here, used for health check. Try /mysfits instead."})
# Returns the data for all of the Mysfits to be displayed on
# the website. If no filter query string is provided, all mysfits are retrived
# and returned. If a querystring filter is provided, only those mysfits are queried.
@app.route("/mysfits")
def getMysfits():
filterCategory = request.args.get('filter')
if filterCategory:
filterValue = request.args.get('value')
queryParam = {
'filter': filterCategory,
'value': filterValue
}
# a filter query string was found, query only for those mysfits.
serviceResponse = mysfitsTableClient.queryMysfits(queryParam)
else:
# no filter was found, retrieve all mysfits.
serviceResponse = mysfitsTableClient.getAllMysfits()
flaskResponse = Response(serviceResponse)
flaskResponse.headers["Content-Type"] = "application/json"
return flaskResponse
# Run the service on the local server it has been deployed to,
# listening on port 8080.
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080)
7