# Python, imitate WebSocket connection comming from Browser

P

#### Patrick

##### Guest
Patrick Asks: Python, imitate WebSocket connection comming from Browser
I am trying to automate an interaction with a game website by communicating with a WebSocket via Python. In particular, I am trying to communicate with the WebSocket at: "wss://socket.colonist.io".

If I simply execute the following JS-code from the browser, I receive the incoming messages as expected:

Code:
ws = new WebSocket('wss://socket.colonist.io');
ws.onmessage = e => {
console.log(e);
}

However, as soon as I am trying to connect to this WebSocket from outside the browser (with Node.JS or with Python), the connection gets immediately closed by the remote. An example using websocket-client in Python can be found below:

Code:
import websocket
def on_message(ws, data):

websocket.enableTrace(True)
socket = websocket.WebSocketApp('wss://socket.colonist.io',
header={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36'},
on_message=on_message)
socket.run_forever(origin='https://colonist.io')
socket.close()

The trace output is the following:

Code:
--- request header ---
GET / HTTP/1.1
Host: socket.colonist.io
Origin: https://colonist.io
Sec-WebSocket-Key: EE3U0EDp36JGZBHWUN5q4Q==
Sec-WebSocket-Version: 13
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36

-----------------------
HTTP/1.1 101 Switching Protocols
Server: nginx/1.18.0 (Ubuntu)
Date: Sat, 24 Sep 2022 17:33:32 GMT
Sec-WebSocket-Accept: EwMJ+z82BuOBOSWONpuOhjNdVCQ=
-----------------------
websocket connected
Connection to remote host was lost. - goodbye

I also tried it using Python-Autobahn and Python-websockets, both with the same negative result.

I suspect the host somehow detects that the connection is not coming from a browser (although, I set a 'User-Agent' and the 'Origin') and therefore closes the connection immediately. Is there any possibility I can connect to this WebSocket from a Script NOT running in a browser? I am aware of the possibility of using Selenium to run and control a browser instance with Python, but I want to avoid this at all cost, due to performance reasons. (I want to control as many WebSocket connections concurrently as possible for my project).

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

#### How to perform feature engineering on columns with multiple categories?

Prateek Coder Asks: How to perform feature engineering on columns with multiple categories?
I want to perform feature engineering on a data that mostly contains textual data and lot of columns with multiple categories like Supervisor, location code, employee class, business unit, job title, etc. What should be the best approach to do this? I have binary encoded the column with 2-3 categories or performed one hot encoding, but these columns contains different categories from 8 to 150. Different location will play major role in prediction, so will the employee class or business unit etc and I believe they will be very important for my model.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

#### [Solved] Create Buffer but keep original Attribute table

J.Beer Asks: Create Buffer but keep original Attribute table
I want to create a buffer around a number of features. It is important for me to keep the attributes of the features in the new buffer.shp layer. When I try to write a new VectorLayer with a QgsVectorFileWriter, I do get the buffered polygons and also the fields of the original layer get copied over, however the attribute table stays empty.

How can I copy over the attributes of the original layer to the buffer layer?

As you can see I already tried to load the attributes using the . attributes() method on the QgsFeature object and setting the attributes. However I feel I am missing something here.

Code:
for f in feats:
attributes = f.attributes()
f.setAttributes(attributes)

See full code below:

Code:
path = '/Volumes/VAW_ETH-Z/M.Thesis/data/geospatial/'

sgi_filtered = QgsVectorLayer(path + 'sgi_filtered.shp')

## Create buffer around filtered sgi
outFn = path + 'gl_buffer3.shp'
bufferDist = 50 # in map units

fields = sgi_filtered.fields()
feats = sgi_filtered.getFeatures()

writer = QgsVectorFileWriter(
outFn,
'utf-8',
fields,
QgsWkbTypes.Polygon,
sgi_filtered.sourceCrs(), # loads the reference system of the source feature
'ESRI Shapefile')

for f in feats:
attributes = f.attributes()
f.setAttributes(attributes)
geom = f.geometry()
buff = geom.buffer(bufferDist, 5)
f.setGeometry(buff)

writer.addFeature(f)

Screenshot of the Attribute Table below (it shows the fields but no attributes):

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, solveforum.

#### [Solved] Saving a Project Folder as a template (QGIS 3.28)

• Ben Sear
• Geography
• Replies: 0
Ben Sear Asks: Saving a Project Folder as a template (QGIS 3.28)
I am looking to create a template for easy layout integration for new QGIS project files, but when saving the project file to a template using save to > template, the file does not appear in the project templates as a template file, but just a new project file. I read that you need to restart GIS once you saved a project file as a template but restarting does not change the project file to being a template. Has anyone experienced saving template before and have any suggestions? Thank you.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, solveforum.

#### Method of cooling a gas without liquid evaporation for Sci-fi novel

• user2765977
• Chemistry
• Replies: 0
user2765977 Asks: Method of cooling a gas without liquid evaporation for Sci-fi novel
sorry for the amateur question here.

I know little about science, but regardless am writing a fictional amateur novel that deals with a lot of chemistry stuff, especially gasses.

My protagonist needs a clever method of cooling a gas. He has access to several gasses (CO2, O2, H2, nitrogen) in varying temperatures (70c and up). Unfortunately no water (at least not more than a few bottles). The atmosphere he is working under (planet atmosphere) is in the range of 150c and at a pressure of roughly 150kpa in the novel.

He also has access to sci-fi style manufacturing machines that can simply 'make' parts, like pipes, valves, pumps, that sort of thing.

I am looking for a clever way or really any way at all, that he can use to cool down some O2 to at least under 40c in such a situation.

My amateur reading online suggests the main way, is via liquid evaporation, but I doubt that would work in the above scenario easily.

Does anybody have any ideas? Is this even possible?

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

#### Is there a "fundamental problem of thermodynamics"?

• agaminon
• Physics
• Replies: 0
agaminon Asks: Is there a "fundamental problem of thermodynamics"?
The "fundamental problem of mechanics" can be boiled down to finding and solving the equation of motion of a system. Similar statements can be said for quantum mechanics for the Schrödinger equation and for electrodynamics and Maxwell's equations, etc. But is there such a thing for thermodynamics? Is there a formulation that allows for this kind of perspective?

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

#### What does this vertical line notation mean?

• Lambda
• Physics
• Replies: 0
Lambda Asks: What does this vertical line notation mean?
Here is the definition of the Noether momentum in my script.

$$I = \left.\frac{\partial L}{\partial \dot{x}} \frac{d x}{d \alpha} \right|_{\alpha=0} = \frac{\partial L}{\partial \dot{x}} = m \dot{x} = p_x.$$ But I don't understand exactly what this vertical line with $\alpha=0$ means, I would have interpreted it as $\frac{dx}{d0}$ now.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

#### Does diffusion of a spring depend on the spring’s equilibrium length?

• Robert S. Pierre
• Physics
• Replies: 0
Robert S. Pierre Asks: Does diffusion of a spring depend on the spring’s equilibrium length?
Say we perform a random walk on $\mathbb{Z}$ with two equal particles that are connected by a spring with spring constant $K$ and equilibrium length $a$, where at each time step each particle has probability $\frac{1}{2}$ of making a step $\pm1$. However, at each step a random number $q\in[0,1]$ is sampled in order to refuse the move if $$q\geq\exp\left(\Delta E\right),$$ where $\Delta E$ is the difference in elastic energy between the two time steps.

Does the diffusion coefficient depend on the equilibrium length $a$?

I know that the diffusion is independent of the spring constant $K$, so we find the same diffusion coefficient for all $K$, namely that of two independent particles. I assume the same holds for the equilibrium length, but is this true and how can I see this?
And furthermore, what role does the initial extension of the spring play? Say the initial length of the spring $x_0$ is not equal to $a$, then the whole system will need a while to equilibrize, as opposed to when we start with $x_0=a$.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.