Python Forum
Can't write to .txt after opening websocket
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't write to .txt after opening websocket
#1
Hi everyone,

When I write to a txt file with this code i get no errors. However after I open a websocket I get a 'type error'
The code I use is:

 def EdtSlist(self): 
     try:
         file1 = open("Slist.txt", "wt")
         test="test"
         file1.write(test) #<--type error
         file1.close()
     except:
         print("Unexpected error:", sys.exc_info()[0])
         raise
Any help is much appreciated because I'm stuck for a while now.
Reply
#2
The only thing it says is "type error"? No traceback?

What's the point of the except section in your code?
Reply
#3
(May-03-2022, 04:04 AM)bowlofred Wrote: The only thing it says is "type error"? No traceback?

What's the point of the except section in your code?

Except is to catch the error:
This is my console output:

EdtSlist gmtusdt
Unexpected error: <class ‘TypeError’>

-------------
When I run just the ‘EdtSlist’ the text gets written to the txt file but when I open a websocket and try to edit text from there it gives me this error. To make sure it wasn't the websocket I closed it before running the ‘EdtSlist’ method but it wouldn't fix the problem.
Reply
#4
file1=open("Slist.txt","a")

gives me:
TypeError: 'str' object is not callable
Reply
#5
Please provide full code and full error message.
Reply
#6
Remove the try/except. You don't do anything to process the error and all the try/ except does is prevent getting a useful error message. Add a "print(open)" command before trying to open the file. What is the output?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to send a pong on websocket-client tomtom 0 3,665 Aug-15-2022, 05:58 AM
Last Post: tomtom
  asyncio calls within sync function ( Websocket on_open) orion67 0 1,421 Jan-16-2022, 11:00 AM
Last Post: orion67
  Help with WebSocket reading data from anoter function korenron 0 1,344 Sep-19-2021, 11:08 AM
Last Post: korenron
  opening a file from a windows desktop folder- error opening file Charan007 1 2,988 Dec-06-2018, 11:50 AM
Last Post: buran
  Data through a websocket darkknight 1 2,406 Sep-28-2017, 08:00 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020