Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the problems related to python?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces in detail "what are the problems related to python", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "what are the problems related to python" can help you solve your doubts.

Question 1:

Why is there nothing behind the raise, as shown in the figure:

This is a piece of source code in Ansible. In general, the raise keyword we see will be followed by an exception, but there is nothing after raise. This situation usually occurs in the except code block, which means that the exception will be thrown back and left to the caller to handle the exception. This code means that if an exception occurs, it tries to handle the exception. If it cannot handle it, it will continue to throw the UnicodeEncodeError. If you have done Mini Program development, you may also encounter similar coding errors.

Question 2:

If flask obtains the real request IP of the client, it will not take effect if it follows the instructions on the Internet.

In fact, most of this problem is that we do not understand the principle. Flask provides an api that can directly obtain the ip, called request.remote_addr, but if our program is deployed with a layer of reverse proxy, such as Nginx, then the return value of remote_addr is 127.0.0.1, because the requests are forwarded by the native nginx. The correct way is to get the client's IP at the Nginx layer, put it in the request Header, and then pass it to Flask.

It depends on the configuration of nginx, for example:

Location / {proxy_set_header Host $host; proxy_set_header X-Real-Ip $remote_addr; proxy_pass http://flask_app/;}

A X-Real-Ip header field is added here, and the value is the real IP,flask of the client. When it is obtained, it can be written as follows:

If request.headers.getlist ("X-Real-Ip"):

Ip = request.headers.getlist ("X-Real-Ip") [0]

Else:

Ip = request.remote_addr

Question 3:

How to get started with python?

In fact, this is already a menstrual problem, every month someone will ask this question, people's common sense, this is the only way for beginners. How to say, there are no shortcuts to learning programming, the key is that you have to put your mind into it, and it takes time to boil it out. Where you spend your time, your skills will be improved. The key problem for beginners is that they don't know how to spend this time. This requires you to explore yourself, find more people to communicate, communicate with those who have been there, and ask them for advice. From getting started to getting started, the routines are all those. First pick an introductory book that you can understand, then practice, find the kind of practical project that you can teach you by hand, and practice together. At least know how to use this step. As for why you use it this way, you can study it later. If it still doesn't, repeat it twice. Where to find training programs, look for more online, look for those projects that you can understand. Finally, use your knowledge points to do a project by yourself, give full play to your creativity, and see if there are any pain points around you that can be realized by program. There is really no, you can go to shanzhai a simple version of v2ex, shanzhai headlines, shanzhai Douban. No one learns to drive by reading books and watching videos. The most important thing is to practice. It is the same in any industry.

After reading this, the article "what are the problems related to python" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report