#twisted

/

      • Guest65574
      • infobob
      • Guest65574
        I keep getting an error line 14 needing to be unicode.
      • when ever I wrap the line iwith the atttrbute .decode('utf-8') i get the error that the function doesn't have that attribute.
      • I was working with asda earlier today and I got most of the errors fixed, this is the alst one i am having an issue getting past.
      • njs
        Guest65574: I think your problem on line 14 is that you have unicode, and need to have bytes
      • Guest65574
        So on line 14 when i try to write.
      • njs
        Guest65574: generally data that's being transmitted over the network needs to be in bytes, so when you receive data you have to decode from bytes→unicode, and when you send data you first encode it from unicode→bytes
      • Guest65574: so try self.transport.write(self.getQuote().encode("utf-8")) # note "encode", not "decode"
      • itamarst has quit
      • Guest65574
        File "C:/Users/Twisted/quoteserver.py", line 14, in dataReceived self.transport.write(self.getQuote().encode("utf-8")) builtins.AttributeError: 'bytes' object has no attribute 'encode'
      • clokep_tb has quit
      • @Guest65574
      • energizer joined the channel
      • this is the error i get when i try that.
      • njs
        Guest65574: well, I'm confused. that's saying that self.getQuote() is returning a 'bytes' object. Which it definitely isn't in the code you pastebinned. On the other hand, if it *is* somehow returning a 'bytes' object, then self.transport.write(self.getQuote()) should have worked, and your complaint was that it didn't. So not sure what's going on :-)
      • Guest65574
        hmmm okay.
      • idk if that is saying that it is returning a bytes object as mch as it might be saying it just doesn't have the ability to use teh function encode?
      • efphe has quit
      • clokep_tb joined the channel
      • EACFreddy
        Guest65574: njs: I think it's because of the self.updateQuote(data) in dataRecieved()
      • njs
        EACFreddy: ah! so without the call to .encode(), it crashes the first time that it reaches line 14. With the call to .encode(), the first time it reaches line 14 it works, then it calls updateQuote(data), which replaces the saved quote with a bytes object, and then the *next* time it reaches line 14 it crashes because *now* getQuote() is returning bytes instead of a str
      • EACFreddy
        using a simple function like this can do the trick: ensure_bytes = lambda s: s if isinstance(s, bytes) else bytes(s, "utf-8")
      • njs
        Guest65574: the error "builtins.AttributeError: 'bytes' object has no attribute 'encode'" is Python telling you exactly that: (a) you tried to do 'someobj.encode', (b) this failed because 'someobj' didn't have an 'encode' attribute, (c) also by the way, 'someobj' was a 'bytes' object (which makes sense, since bytes objects never have an encode method)
      • EACFreddy: that's a terrible habit though :-(
      • Guest65574
        interesting.
      • okay let me see i understand this right.
      • so in quote server my data is in byte?
      • where do i put the cod e you wrote?
      • EaC freddy?
      • EACFreddy
        if you want clean code, nowhere and instead make it a habit to only use bytes everywhere
      • Guest65574
        How do i ensure I am using bytes?
      • EACFreddy
        b"something" instead of "something"
      • Guest65574
        where would i put the b? The weird thing is that the program is printing what I want it to print. so idk the point of the error.
      • njs
        if you want clean code, make it a habit to decode text on input and encode it on output :-P
      • Guest65574
        I FIXED IT Yay.
      • so I needed a "b" on line 30 in the quote factory class.
      • not in line 14.
      • can someone expalin to me why it was throwing out the error in such an odd place?
      • Yhg1s has quit
      • rakiru_ joined the channel
      • Yhg1s joined the channel
      • znpy has quit
      • EACFreddy has quit
      • EACFreddy joined the channel
      • Guest65574 has quit
      • znpy joined the channel
      • altendky has quit
      • rodrigc joined the channel
      • rodrigc
        Looks like buildbot.twistedmatrix.com is down
      • altendky joined the channel
      • Hasimir joined the channel
      • kenaan
        Tickets pending review: https://tm.tl/#7495, #9299, #9305, #9333, #9337, #9338, #9340, #9343 (rodrigc), #9350 (ktdreyer), #9210 (markrwilliams), #9358, #9353, #9362, #9365 (axiaoxin), #8966 (the0id), #9100, #9118 (the0id), #4964 (jameshilliard), #9138, #9176
      • rodrigc has quit
      • oberstet joined the channel
      • markb1 has quit
      • epopt has quit
      • oberstet has quit
      • Tickets pending review: https://tm.tl/#7495, #9299, #9305, #9333, #9337, #9338, #9340, #9343 (rodrigc), #9350 (ktdreyer), #9210 (markrwilliams), #9358, #9353, #9362, #9365 (axiaoxin), #8966 (the0id), #9100, #9118 (the0id), #4964 (jameshilliard), #9138, #9176
      • yuhl joined the channel
      • oberstet joined the channel
      • __marco joined the channel
      • __marco__ joined the channel
      • __marco__ has quit
      • __marco joined the channel
      • oberstet has quit
      • oberstet joined the channel
      • Hasimir has quit
      • Hasimir joined the channel
      • __marco__ joined the channel
      • __marco has quit
      • sveinse
        I'm writing a small oneshot client which shall print its output to stdout. However the client use twisted.logger for its output. This is fine for the server, since it captures stdout, but for the client this isn't how I want this. How can I relate to the logger in a client application?
      • Can I configure twister.logger.Logger() not to capture stdout, so print could work as-is?
      • efphe joined the channel
      • verterok joined the channel
      • clokep_tb joined the channel
      • verterok has quit
      • verterok joined the channel
      • slav0nic joined the channel
      • markb1 joined the channel
      • terrycojones joined the channel
      • nchambers joined the channel
      • terrycojones has quit
      • __marco joined the channel
      • __marco__ has quit
      • kenaan
        Tickets pending review: https://tm.tl/#7495, #9299, #9305, #9333, #9337, #9338, #9340, #9343 (rodrigc), #9350 (ktdreyer), #9210 (markrwilliams), #9358, #9353, #9362, #9365 (axiaoxin), #8966 (the0id), #9100, #9118 (the0id), #4964 (jameshilliard), #9138, #9176
      • kolko has quit
      • itamarst joined the channel
      • oberstet2 joined the channel
      • oberstet has quit
      • __marco__ joined the channel
      • __marco has quit
      • __marco__ has quit
      • __marco__ joined the channel
      • __marco joined the channel
      • __marco__ has quit
      • terrycojones joined the channel
      • __marco has quit
      • __marco joined the channel
      • __marco has quit
      • bitranch_ has quit
      • __marco joined the channel
      • __marco has quit
      • __marco__ joined the channel
      • terrycojones joined the channel
      • humanoide joined the channel
      • humanoide has left the channel
      • efphe has quit
      • terrycojones has quit
      • terrycojones joined the channel
      • terrycojones has quit
      • terrycojones joined the channel
      • __marco__ has quit
      • iffy joined the channel
      • terrycojones joined the channel
      • terrycojones has quit
      • terrycojones joined the channel
      • terrycojones has quit
      • terrycojones joined the channel
      • terrycojones has quit
      • jamesaxl joined the channel
      • LichtMacher joined the channel
      • yuhl joined the channel
      • yuhl has quit
      • Hasimir joined the channel
      • mesozoic has quit
      • mesozoic joined the channel
      • epopt joined the channel
      • energizer joined the channel
      • mesozoic has quit
      • mesozoic joined the channel
      • yuhl joined the channel
      • deepy has quit
      • Tickets pending review: https://tm.tl/#7495, #9299, #9305, #9333, #9337, #9338, #9340, #9343 (rodrigc), #9350 (ktdreyer), #9210 (markrwilliams), #9358, #9353, #9362, #9365 (axiaoxin), #8966 (the0id), #9100, #9118 (the0id), #4964 (jameshilliard), #9138, #9176
      • deepy joined the channel
      • terrycojones joined the channel
      • efphe joined the channel
      • clokep_tb has quit
      • iffy has quit
      • iffy joined the channel
      • iffy has quit
      • LionsMane joined the channel
      • slav0nic has quit
      • archer0001 has quit
      • jamesaxl has quit
      • twm
        sveinse: Yes, pass redirectStandardIO=False http://twistedmatrix.com/documents/current/api/...
      • wgrant has quit
      • wgrant joined the channel
      • mwhudson has quit
      • mwhudson joined the channel