英文:
How can I use special chars in Python Azure Function?
问题
我有一个Azure函数(Python),我需要在request.params中获取特殊字符。
我想要接受的URL是"http://localhost:7071/api/testApp?Status>3"。
我的Python代码如下:
def main(req: func.HttpRequest) -> func.HttpResponse:
try:
Metadata = MetadataOperations()
result = Metadata.get_items(req.params)
这是我得到的:
当URL是"http://localhost:7071/api/testApp?Status=3"时,一切都正常工作。
为了接受'>'字符,我应该怎么做?
谢谢。
英文:
I have an Azure Function (Python) and I need to get special chars in the request.params.
The URL I want to accept is "http://localhost:7071/api/testApp?Status>3"
My Python code is below:
def main(req: func.HttpRequest) -> func.HttpResponse:
try:
Metadata = MetadataOperations()
result = Metadata.get_items(req.params)
This is what I get:
When the URL is "http://localhost:7071/api/testApp?Status=3" everything is working fine.
What should I do in order to accept '>' chars?
Thanks.
答案1
得分: 1
以下是翻译好的部分:
>如何在Python Azure函数中使用特殊字符?
我同意@Klaus D.的看法,我在我的环境中重现了这个问题,以下是我的观察结果。
你不能直接在URL中使用**>
**。但你可以通过以下方式使用:
__init__.py
import azure.functions as func
import urllib.parse
def main(req: func.HttpRequest) -> func.HttpResponse:
try:
decpar = {k1: urllib.parse.unquote(v1) for k1, v1 in req.params.items()}
return func.HttpResponse(f"Received query parameters are/Sent Parameters are: {decpar}", status_code=200)
except Exception as ee:
return func.HttpResponse(f"Error: {str(ee)}", status_code=500)
http://localhost:7071/api/HttpTrigger1?Status=%3E3
你需要像这样提供:?Status=%3E3
http://localhost:7071/api/HttpTrigger1?Status=%3E3
输出:
这样你就可以使用**>
**,但不能直接使用。
英文:
>How can I use special chars in Python Azure Function?
I do agree with @Klaus D. and I have reproduced in my environment and below are my observations.
You cannot directly use >
it in URL. But you can in below way:
__init__.py
import azure.functions as func
import urllib.parse
def main(req: func.HttpRequest) -> func.HttpResponse:
try:
decpar = {k1: urllib.parse.unquote(v1) for k1, v1 in req.params.items()}
return func.HttpResponse(f"Received query parameters are/Sent Parameters are: {decpar}", status_code=200)
except Exception as ee:
return func.HttpResponse(f"Error: {str(ee)}", status_code=500)
http://localhost:7071/api/HttpTrigger1?Status=%3E3
You need to give like this : ?Status=%3E3
http://localhost:7071/api/HttpTrigger1?Status=%3E3
Output:
This way you can use >
but not directly.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论