代码:
import os
import random
import time
import requests
from appetizer import Appetizer结果:
Traceback (most recent call last):
File "C:/GITHUB/stress_testing/main.py", line 5, in <module>
from appetizer import Appetizer
File "C:\GITHUB\stress_testing\venv\lib\site-packages\appetizer\__init__.py", line 17, in <module>
from .appetizer import Appetizer
File "C:\GITHUB\stress_testing\venv\lib\site-packages\appetizer\appetizer.py", line 76
"""
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 292-293: truncated \UXXXXXXXX escapeappetizer.py文件中的76行:
def detect_adb(self):
""" Detect the path to the adb tool from the Android SDK
:return: A JSON object. For example: {'adb': '/home/myuser/Android/Sdk/platform-tools/adb'}
Note that the path could be a unicode string.
The default installation paths for different OSes are:
Windows: C:\Users\<User Name>\AppData\Local\Android\sdk\platform-tools\
Linux: /home/<User Name>/Android/Sdk/platform-tools/adb
"""
return json.loads(self.appetizer.check_output(["adb", "detectadb"]))我知道"\“(Windows路径中的双"\”)、"/“等等。但是在我做某些事情之前,我有错误--在进口阶段。我该换什么,在哪里换?我试过用虚拟的env和通用的。
发布于 2018-05-08 12:54:49
它实际上告诉你出了什么问题。在代码的第76行中,函数定义中有一个\uxxxxxxx转义字符,其长度无效,位于292-293位置。
下列措施将起作用:
stri = """ Detect the path to the adb tool from the Android SDK
:return: A JSON object. For example: {'adb': '/home/myuser/Android/Sdk/platform-tools/adb'}
Note that the path could be a unicode string.
The default installation paths for different OSes are:
Windows: C:\\Users\<User Name>\AppData\Local\Android\sdk\platform-tools\
Linux: /home/<User Name>/Android/Sdk/platform-tools/adb
"""
stri[292] #'\\'
stri[293] #'U'鉴于:
stri = """ Detect the path to the adb tool from the Android SDK
:return: A JSON object. For example: {'adb': '/home/myuser/Android/Sdk/platform-tools/adb'}
Note that the path could be a unicode string.
The default installation paths for different OSes are:
Windows: C:\Users\<User Name>\AppData\Local\Android\sdk\platform-tools\
Linux: /home/<User Name>/Android/Sdk/platform-tools/adb
"""
#SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 292-293: truncated \UXXXXXXXX escape这种行为的原因是(下次请指出相关的包) 重放工具包是为Python2.7编写的,其中'\U'将顺利通过。您必须检查源代码,并使用双反斜杠或正斜杠手动替换这些序列。
https://stackoverflow.com/questions/50232576
复制相似问题