Soaplib2.0.0beta + django和1C连接错误

发布于 2024-11-05 05:47:39 字数 3249 浏览 0 评论 0原文

我在 Django 中有任务启动肥皂服务(用于从商业软件接收数据)

已经安装了soaplib2.0.0beta并从soap到django制作了层(使用Django Snippets) 创建了一些肥皂方法和数据类型。一切都适用于 suds (lib) 测试,但在生产中收到错误。

错误表示某些列不是唯一的,但数据没问题并且方法可以连接到数据库(.all().count() 测试)。

我认为层或 nginx 的配置有错误...

层代码:

# Code of Layer:
class DjangoSoapApp(Application):
    def __call__(self, request):
        # wrap the soaplib response into a Django response object
        django_response = HttpResponse()
        def start_response(status, headers):
            status, reason = status.split(' ', 1)
            django_response.status_code = int(status)
            for header, value in headers:
                django_response[header] = value
        response = super(DjangoSoapApp, self).__call__(request.META, start_response)
        django_response.content = '\n'.join(response)
        return django_response

方法代码:

# Method's code
class SyncService(DefinitionBase):

    @rpc(User, Order, _returns=Array(Response))
    def CreateOrder(self, user=None, order=None):
        response = []

        # response.append(Response(Result = True, Response = "ORDERS: " + str(self.tmp.count())))
        # return response

        if not user or not order:
            response.append(Response(Result = False, Response = "Exception: not send user or order"))
            return response
        try:
            new_user = user_model.objects.get(commerce_uid=user.Id)
            response.append(Response(Result = True, Response="Success: Get user %s %s" % (user.Name, user.EMail)))
        except Exception as e:
            try:
                new_user = user_model(
                    email=user.EMail,
                    commerce_uid=user.Id,
                    telephone=user.Phone,
                    name=user.Name,
                    username=re.sub(r'\.|\@', '', user.EMail),
                    isSync = True)
                new_user.save()
                response.append(Response(Result = True,Response = "Success: Create user %s %s" % (user.Name, user.EMail)))
            except Exception as e:
                response.append(Response(Result = False, Response = "Exception: user '%s' not found and can't create (%s)" % (user, e)))
                return response

        try:
            new_order = order_model(
                user=new_user,
                date=order.Date,
                time=order.Time,
                boat=order.Boat,
                amount=order.Quantity,
                isSync=True
            )
            new_order.save()
            response.append(Response(Result = True, Response = "Success: Create order %s" % (order)))
        except Exception as e:
            response.append(Response(Result = False, Response = "Exception: Can't create order '%s' for user '%s' (%s)" % (order, user, e)))
            return response

        return response

错误示例:

Exception: user 'Id: 6d73d109-4b7b-453e-819a-94c42a883c09, Name: John Smith 2, Email: [email protected], Phone: +749512345679' not found and can't create (column commerce_uid is not unique)

I have task get up soap service in Django (for receive data from commerce software)

Have been installed soaplib2.0.0beta and made layer from soap to django (use Django Snippets)
Created some soap-methods and data types. Everything works with suds (lib) test, but receive errors in production.

Erorrs says some column is not unique, but data is okey and method can connect to db (.all().count() test).

I think mistake in layer or nginx's config...

Code of Layer:

# Code of Layer:
class DjangoSoapApp(Application):
    def __call__(self, request):
        # wrap the soaplib response into a Django response object
        django_response = HttpResponse()
        def start_response(status, headers):
            status, reason = status.split(' ', 1)
            django_response.status_code = int(status)
            for header, value in headers:
                django_response[header] = value
        response = super(DjangoSoapApp, self).__call__(request.META, start_response)
        django_response.content = '\n'.join(response)
        return django_response

Method's code:

# Method's code
class SyncService(DefinitionBase):

    @rpc(User, Order, _returns=Array(Response))
    def CreateOrder(self, user=None, order=None):
        response = []

        # response.append(Response(Result = True, Response = "ORDERS: " + str(self.tmp.count())))
        # return response

        if not user or not order:
            response.append(Response(Result = False, Response = "Exception: not send user or order"))
            return response
        try:
            new_user = user_model.objects.get(commerce_uid=user.Id)
            response.append(Response(Result = True, Response="Success: Get user %s %s" % (user.Name, user.EMail)))
        except Exception as e:
            try:
                new_user = user_model(
                    email=user.EMail,
                    commerce_uid=user.Id,
                    telephone=user.Phone,
                    name=user.Name,
                    username=re.sub(r'\.|\@', '', user.EMail),
                    isSync = True)
                new_user.save()
                response.append(Response(Result = True,Response = "Success: Create user %s %s" % (user.Name, user.EMail)))
            except Exception as e:
                response.append(Response(Result = False, Response = "Exception: user '%s' not found and can't create (%s)" % (user, e)))
                return response

        try:
            new_order = order_model(
                user=new_user,
                date=order.Date,
                time=order.Time,
                boat=order.Boat,
                amount=order.Quantity,
                isSync=True
            )
            new_order.save()
            response.append(Response(Result = True, Response = "Success: Create order %s" % (order)))
        except Exception as e:
            response.append(Response(Result = False, Response = "Exception: Can't create order '%s' for user '%s' (%s)" % (order, user, e)))
            return response

        return response

Sample of error:

Exception: user 'Id: 6d73d109-4b7b-453e-819a-94c42a883c09, Name: John Smith 2, Email: [email protected], Phone: +749512345679' not found and can't create (column commerce_uid is not unique)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文