来自 Python 脚本的错误 运行 trueaccord.scalapb TypeError
Error running trueaccord.scalapb TypeError from Python script
我正在尝试 运行 https://github.com/aegnor/scalapb-maven-example 中的示例
pom.xml 不适合我 运行 除非我做一些改变:
<dependency>
<groupId>com.trueaccord.scalapb</groupId>
<artifactId>scalapbc_2.11</artifactId>
<version>0.6.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<!-- Generating Scala code on Windows requires Python 2.x to be installed on your system. -->
<id>generate-scala-protobuf-classes</id>
<goals>
<goal>java</goal>
</goals>
<phase>generate-sources</phase>
</execution>
</executions>
<configuration>
<mainClass>com.trueaccord.scalapb.ScalaPBC</mainClass>
<includeProjectDependencies>true</includeProjectDependencies>
<includePluginDependencies>false</includePluginDependencies>
<classpathScope>compile</classpathScope>
<executableDependency>
<groupId>com.trueaccord.scalapb</groupId>
<artifactId>scalapbc_2.11</artifactId>
</executableDependency>
<arguments>
<argument>--proto_path=${project.basedir}/src/main/proto</argument>
<argument>--scala_out=${project.build.directory}/generated-sources/proto</argument>
<argument>${project.basedir}/src/main/proto/*.proto</argument>
</arguments>
</configuration>
</plugin>
我所做的是添加 com.trueaccord.scalapb 依赖项并在此之后设置为 true includeProjectDependencies 它实际上是 运行s。但是现在我收到一条错误消息:
Traceback (most recent call last):
File "C:\Users\JoseO\AppData\Local\Temp\protocbridge1191463098726442484.py", line 6,
in <module>
s.sendall(content)
TypeError: a bytes-like object is required, not 'str'
--scala_out: protoc-gen-scala: Plugin failed with status code 1.
现在我从插件中捕获生成的代码。会生成两个文件来执行命令:
protoc-jar: executing: [C:\Users\user\AppData\Local\Temp\protocjar3115202540073112270\bin\protoc.exe, --plugin=protoc-gen-scala=C:\Users\user\AppData\Local\Temp\protocbridge875241605176874095.bat, --proto_path=C:\dev\examples\scalapb-maven-example/src/main/proto, --scala_out=C:\dev\examples\scalapb-maven-example\target/generated-sources/proto, C:\dev\examples\scalapb-maven-example/src/main/proto/*.proto]
第一个文件是批处理文件:
@echo off
python.exe -u C:\Users\user\AppData\Local\Temp\protocbridge8364859980217271731.py 60354
第二个是phyton文件,这是错误发生的地方。
import sys, socket
content = sys.stdin.read()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', int(sys.argv[1])))
s.sendall(content)
s.shutdown(socket.SHUT_WR)
while 1:
data = s.recv(1024)
if data == '':
break
sys.stdout.write(data)
s.close()
谁能告诉我哪里出了问题?
这里的问题是插件 com.trueaccord.scalapb:scalapbc_2.11:0.6.6 使用 Python 版本 2 而我已经安装了 Python 版本 3。一次我重新安装了正确的版本,一切正常。
我正在尝试 运行 https://github.com/aegnor/scalapb-maven-example 中的示例 pom.xml 不适合我 运行 除非我做一些改变:
<dependency>
<groupId>com.trueaccord.scalapb</groupId>
<artifactId>scalapbc_2.11</artifactId>
<version>0.6.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<!-- Generating Scala code on Windows requires Python 2.x to be installed on your system. -->
<id>generate-scala-protobuf-classes</id>
<goals>
<goal>java</goal>
</goals>
<phase>generate-sources</phase>
</execution>
</executions>
<configuration>
<mainClass>com.trueaccord.scalapb.ScalaPBC</mainClass>
<includeProjectDependencies>true</includeProjectDependencies>
<includePluginDependencies>false</includePluginDependencies>
<classpathScope>compile</classpathScope>
<executableDependency>
<groupId>com.trueaccord.scalapb</groupId>
<artifactId>scalapbc_2.11</artifactId>
</executableDependency>
<arguments>
<argument>--proto_path=${project.basedir}/src/main/proto</argument>
<argument>--scala_out=${project.build.directory}/generated-sources/proto</argument>
<argument>${project.basedir}/src/main/proto/*.proto</argument>
</arguments>
</configuration>
</plugin>
我所做的是添加 com.trueaccord.scalapb 依赖项并在此之后设置为 true includeProjectDependencies 它实际上是 运行s。但是现在我收到一条错误消息:
Traceback (most recent call last):
File "C:\Users\JoseO\AppData\Local\Temp\protocbridge1191463098726442484.py", line 6,
in <module>
s.sendall(content)
TypeError: a bytes-like object is required, not 'str'
--scala_out: protoc-gen-scala: Plugin failed with status code 1.
现在我从插件中捕获生成的代码。会生成两个文件来执行命令:
protoc-jar: executing: [C:\Users\user\AppData\Local\Temp\protocjar3115202540073112270\bin\protoc.exe, --plugin=protoc-gen-scala=C:\Users\user\AppData\Local\Temp\protocbridge875241605176874095.bat, --proto_path=C:\dev\examples\scalapb-maven-example/src/main/proto, --scala_out=C:\dev\examples\scalapb-maven-example\target/generated-sources/proto, C:\dev\examples\scalapb-maven-example/src/main/proto/*.proto]
第一个文件是批处理文件:
@echo off
python.exe -u C:\Users\user\AppData\Local\Temp\protocbridge8364859980217271731.py 60354
第二个是phyton文件,这是错误发生的地方。
import sys, socket
content = sys.stdin.read()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', int(sys.argv[1])))
s.sendall(content)
s.shutdown(socket.SHUT_WR)
while 1:
data = s.recv(1024)
if data == '':
break
sys.stdout.write(data)
s.close()
谁能告诉我哪里出了问题?
这里的问题是插件 com.trueaccord.scalapb:scalapbc_2.11:0.6.6 使用 Python 版本 2 而我已经安装了 Python 版本 3。一次我重新安装了正确的版本,一切正常。