Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8505535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:20:55+00:00 2026-06-11T02:20:55+00:00

I’m learning twisted so I can integrate it with a blackjack pygame I have.

  • 0

I’m learning twisted so I can integrate it with a blackjack pygame I have. When figuring out how to pass the data from one client to server and then to other clients I was trying to see how I could manipulate the strings that normally get printed to the terminal in each clients screen in this example:

When I say manipulate, I mean to change the datatype to list, int, tuple, etc. of the ‘data’, print information of it (type(data)), and have conditionals for any keywords.

from twisted.internet import stdio, reactor, protocol
from twisted.protocols import basic
import re

## when client receives data from server // the client script checks then blits ##

class DataForwardingProtocol(protocol.Protocol):
    def __init__(self):
        self.output = None
        self.normalizeNewlines = False

    def dataReceived(self,data):
        if self.normalizeNewlines:

    ## see if data is == to secret ##
    ## this never returns True ? ##
            if data == 'secret':
                print "This line isn't secure"
            else:
                data = re.sub(r"(\r\n|\n)","\r\n",data)
        if self.output:
            if data == "secret":
                print "This line isn't secure"
            else:

         ## this will return the error message below ##
         ## so I'm very unsure of what is going on with 'data' ##
                self.output.write(type(data))

class StdioProxyProtocol(DataForwardingProtocol):
    def connectionMade(self):
        inputForwarder = DataForwardingProtocol()
        inputForwarder.output = self.transport
        inputForwarder.normalizeNewlines = True
        stdioWrapper = stdio.StandardIO(inputForwarder)
        self.output = stdioWrapper

class StdioProxyFactory(protocol.ClientFactory):
    protocol = StdioProxyProtocol

reactor.connectTCP('192.168.1.2', 6000, StdioProxyFactory())
reactor.run()

Returns:

Unhandled Error
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/twisted/python/log.py", line 84, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/twisted/python/log.py", line 69, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/twisted/python/context.py", line 118, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/twisted/python/context.py", line 81, in callWithContext
    return func(*args,**kw)
--- <exception caught here> ---
  File "/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.py", line 614, in _doReadOrWrite
    why = selectable.doRead()
  File "/usr/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 203, in doRead
    return self._dataReceived(data)
  File "/usr/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 209, in _dataReceived
    rval = self.protocol.dataReceived(data)
  File "Downloads/trial.py", line 22, in dataReceived
    self.output.write(type(data))
  File "/usr/lib/python2.7/dist-packages/twisted/internet/_posixstdio.py", line 53, in write
    self._writer.write(data)
  File "/usr/lib/python2.7/dist-packages/twisted/internet/process.py", line 174, in write
    abstract.FileDescriptor.write(self, data)
  File "/usr/lib/python2.7/dist-packages/twisted/internet/abstract.py", line 335, in write
    self._tempDataLen += len(data)
exceptions.TypeError: object of type 'type' has no len()

So I can never ‘check’ the ‘data’ and when I try to print out anything about the data or change its type I get an extensive error? Is there something obvious I’m missing or is this the wrong way to even go about it? If it helps here is the server script

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:20:57+00:00Added an answer on June 11, 2026 at 2:20 am

    When you call type() it returns the type of the object, and not a string representing the type of the object.

    You could check the type like this instead:

    >>> aString = 'abc'
    >>> anInt = 123
    >>> type(aString) is str
    True
    >>> type(aString) is int
    False
    >>> type(anInt) is str
    False
    >>> type(anInt) is int
    True
    

    The data you receive will not be a list, tuple or some other kind of object unless you serialize it. Check out the module Pickle to see examples of how you can serialize objects!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.