VxCoder opened a new issue #8259: URL: https://github.com/apache/skywalking/issues/8259
### Search before asking - [X] I had searched in the [issues](https://github.com/apache/skywalking/issues?q=is%3Aissue) and found no similar issues. ### Apache SkyWalking Component Python Agent (apache/skywalking-python) ### What happened my package info: apache-skywalking 0.7.0 Flask 1.1.4 uWSGI 2.0.19.1 my deploy info: nginx -> uwsgi -> flask my init code: ``` agent.config.service_name = service_name agent.config.disable_plugins = ["sw_psycopg2"] agent.config.logging_level = logging.ERROR # ignore plugin failed info agent.start() agent.config.logging_level = logging.INFO ``` when handle a simple request, I got error ``` ERROR - msg:Exception on /api/public_key [GET] Traceback (most recent call last): File "/usr/local/python3/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File "/usr/local/python3/lib/python3.8/site-packages/skywalking/plugins/sw_flask.py", line 57, in _sw_full_dispatch_request span.peer = '%s:%s' % (req.environ["REMOTE_ADDR"], req.environ["REMOTE_PORT"]) KeyError: 'REMOTE_PORT' ``` ### What you expected to happen I find the code in sw_flask.py in line 57 is ` span.peer = '%s:%s' % (req.environ["REMOTE_ADDR"], req.environ["REMOTE_PORT"])` when "REMOTE_PORT" is not exsit, get this excepiton. And as [how-to-use-flask-get-clients-port](https://stackoverflow.com/questions/34785337/how-to-use-flask-get-clients-port) said, the REMOTE_PORT in some time may be miss. so I think the simple fix is like: ` span.peer = f"{req.environ.get('REMOTE_ADDR', 'UNKNOW')}:{req.environ.get('REMOTE_PORT', 'UNKNOW')}"` ### How to reproduce I just ran flask behind a nginx got this bug. ### Anything else _No response_ ### Are you willing to submit PR? - [X] Yes I am willing to submit a PR! ### Code of Conduct - [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
