Skip to content

Commit

Permalink
Check for python version to avoid converting target to bytes in python3
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Mulube committed Oct 1, 2018
1 parent f78d038 commit b8d6879
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion protoc-gen-twirp_python/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (g *generator) generateFile(file *descriptor.FileDescriptorProto) *plugin.C
g.P(` from urllib.error import HTTPError`)
g.P(`import json`)
g.P(`from google.protobuf import symbol_database as _symbol_database`)
g.P(`import sys`)
g.P()
g.P(`_sym_db = _symbol_database.Default()`)
g.P()
Expand Down Expand Up @@ -134,7 +135,10 @@ func (g *generator) generateProtobufClient(file *descriptor.FileDescriptorProto,
g.P(` server_address: The address of the server to send requests to, in`)
g.P(` the full protocol://host:port form.`)
g.P(` """`)
g.P(` self.__target = server_address.encode('ascii')`)
g.P(` if sys.version_info[0] > 2:`)
g.P(` self.__target = server_address`)
g.P(` else:`)
g.P(` self.__target = server_address.encode('ascii')`)
g.P(` self.__service_name = `, strconv.Quote(fullServiceName(file, service)))
g.P()
g.P(` def __make_request(self, body, full_method):`)
Expand Down

0 comments on commit b8d6879

Please sign in to comment.