可以发送字符串,但别无其他

时间:2019-10-14 13:00:05

标签: python

我正在尝试让服务器在接收到GETALL作为输入时返回thisdict,但是直接给定字符串之外的任何内容都不起作用。我怀疑编码,但似乎不是打破它的人。有什么建议吗?

最初,编码是ASCII和UTF-8的变体,但为简单起见,我将其全部更改为UTF-8。

        this.canSeeChart = this.websites.length <= 10 || this.noCaption;
        this.intervalDataSubscription = this.intervalService.getSharedIntervalDataObservable().subscribe((intervalData => {
            this.intervalData = intervalData;
            this.beforePost();
        }));
        this.chart = this.chartService.getChartTypeInterfaceByEnum(this.chartType);
        this.fragmentSubscription = this.route.fragment.subscribe(fragment => {
            this.showPlotly = this.chart.hash === fragment;
        });

1 个答案:

答案 0 :(得分:1)

(显然)您的问题在这里:

connection.send(str(thisdict) + "".encode('utf-8'))

这是类型的例外

TypeError: can only concatenate str (not "bytes") to str

您没有看到此异常,因为您正在捕获它并执行pass

您想要的是将""连接起来,然后进行编码,例如:

connection.send((str(thisdict) + "").encode('utf-8'))