python-3.x - 如何继续使用 IF 并使用 Python3
问题描述
在这两种情况下我都需要继续。如果为假,则继续,如果为真,则运行 GetSess... 并继续。
下面的代码如果 UNKNOWN,执行并在 else: 处停止。它不循环。尝试了很多方法来修复,但仍然无法正常工作。
(已编辑)
if gsid.find("OverAllDescription").text == 'UNKNOWN':
GetSessId = '<?xml version="1.0" encoding="UTF-8"?> <OSS xmlns="http://www.zhone.com/OSSXML" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.zhone.com/OSSXML ossxml.xsd"> <Request> <RequestType>authenticate</RequestType> </Request> <RequestElement> <Attribute> <Name>loginName</Name> <Value>zmstest</Value> </Attribute> <Attribute> <Name>password</Name> <Value>zmstest</Value> </Attribute> </RequestElement> </OSS>\n'
s.sendall(GetSessId.encode('utf-8'))
response = s.recv(10240)
print(response)
gsidr = ET.fromstring(response)
sessid = gsidr.findall("ResponseElement/SessionID")[0].text
#print(sessid)
else:
code
我需要类似的东西:
如果 gsid != 'UNKNOWN'continue 并且如果 gsid == 'UNKNOWN',运行 GetSess... 并继续。
解决方案
if gsid.find("OverAllDescription").text != 'UNKNOWN':
continue
else:
GetSessId = '<?xml version="1.0" encoding="UTF-8"?> <OSS xmlns="http://www.zhone.com/OSSXML" xmlns:xsi`enter code here`="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.zhone.com/OSSXML ossxml.xsd"> <Request> <RequestType>authenticate</RequestType> </Request> <RequestElement> <Attribute> <Name>loginName</Name> <Value>zmstest</Value> </Attribute> <Attribute> <Name>password</Name> <Value>zmstest</Value> </Attribute> </RequestElement> </OSS>\n'
s.sendall(GetSessId.encode('utf-8'))
response = s.recv(10240)
#print(response)
gsidr = ET.fromstring(response)
sessid = gsidr.findall("ResponseElement/SessionID")[0].text
#print(sessid)
推荐阅读
- android - 如果应用程序不在主屏幕中,如何使用 adb 命令打开应用程序?
- javascript - 在 Google Maps Javascript API 中为 Places API 构建查询 URL
- javascript - 如何在报告中设置过滤器 Power BI 嵌入式 javascript
- android - 如何为 GridLayoutManager 使用 ItemDecoration
- c# - 如何在 .net 核心休息服务中实现基本身份验证和授权?
- android - 是否可以通过同一个谷歌帐户在数千台平板电脑上安装系统应用程序?
- php - 使用根索引文件访问 laravel 公用文件夹
- c# - 为什么天蓝色搜索会在 IndexingResults 中抛出 IndexBatchException 而没有失败
- uwp - 在 UWP 清单文件中包含语句
- jquery - 如何在 ajax 成功中将 id 传递给我的打印页面