在Python中执行cURLs命令行
我通过PHP生成了Python文件在Python中执行cURLs命令行,python,curl,Python,Curl,我通过PHP生成了Python文件 import os #state = 6f28bbc4-623a-4424-86df-76e10e82169d #nonce = 6ff7995b-8425-4a66-bb9c-1671557e5778 cmd = 'curl -c session_cookies.txt "https://login.uat.site.be/openid/oauth/authorize?client_id=site&state=6f28bbc4-623a-4424
import os
#state = 6f28bbc4-623a-4424-86df-76e10e82169d
#nonce = 6ff7995b-8425-4a66-bb9c-1671557e5778
cmd = 'curl -c session_cookies.txt "https://login.uat.site.be/openid/oauth/authorize?client_id=site&state=6f28bbc4-623a-4424-86df-76e10e82169d&nonce6ff7995b-8425-4a66-bb9c-1671557e5778&response_type=code&claims=%7B%22id_token%22%3A%7B%22http%3A%2F%2Fsite.be%2Fclaims%2Froles%22%3Anull%7D%7D" 2>/dev/null| curl -v -b session_cookies.txt -L -H "Content-Type: application/x-www-form-urlencoded" -v -d 'j_username=manager-sitelogin@gmail.com&j_password=site1' "https://login.uat.site.be/openid/login.do" 2>&1 >/dev/null | grep Location | grep code= '
os.system(cmd)
我不断得到
语法错误:无效语法
。它有这么多单引号内的双引号,我不知道我做错了什么。我已经尝试使用\'
来逃避它。当您查看块代码中的颜色时,可以直接看到问题
j_username=manager-sitelogin@gmail...
为黑色,而字符串的其余部分为红色,因为'
之前的j_username
会过早关闭字符串
您可以使用“string”
语法,如下所示:
啊。。。好把戏。现在将其添加到我的python技能工具箱中。谢谢你,埃里克。
cmd = """curl -c session_cookies.txt "https://login.uat.site.be/openid/oauth/authorize?client_id=benu&state=6f28bbc4-623a-4424-86df-76e10e82169d&nonce6ff7995b-8425-4a66-bb9c-1671557e5778&response_type=code&claims=%7B%22id_token%22%3A%7B%22http%3A%2F%2Fsite.be%2Fclaims%2Froles%22%3Anull%7D%7D" 2>/dev/null| curl -v -b session_cookies.txt -L -H "Content-Type: application/x-www-form-urlencoded" -v -d 'j_username=manager-sitelogin@gmail.com&j_password=site1' "https://login.uat.site.be/openid/login.do" 2>&1 >/dev/null | grep Location | grep code= """