question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FastHttpUser error: only SOCK_STREAM type sockets are supported

See original GitHub issue

The code:

`import json from locust import SequentialTaskSet, task, constant from locust.contrib.fasthttp import FastHttpUser from locust import LoadTestShape

class Hong(SequentialTaskSet): @task def api_community_list(self): headers = {‘Content-Type’: ‘application/x-www-form-urlencoded’,‘tenantId’: ‘22’, “host”: “countyrmt-test-api.thecover.cn”} r_url = “/community/list” data = json.dumps({“page_size”: 10, “type”: 1}) requests_data = {“data”: data, ‘deviceid’: ‘1B722294-E6B7-4AB0-B60A-84AB9972BBCA-ODBD’, ‘token’: ‘e3620bae8bfb4d56902701466901ee93’, ‘optionName’: “test”} with self.client.post(r_url, data=requests_data, catch_response=True, name=r_url, headers=headers) as r: if r.content == b"": r.failure(“No data”) if r.status_code != 200: em = “request error --” + str(r.status_code) r.failure(em)

class LocustHljLocust(FastHttpUser): host = “http://123.4.28.255:80” wait_time = constant(0) tasks = {Hong: 1}`

An error occurred while passing headers in the request parameter:

[2020-12-22 17:26:08,722] thecovercs/ERROR/locust.user.task: only SOCK_STREAM type sockets are supported Traceback (most recent call last): File “d:\python\lib\site-packages\locust\user\task.py”, line 290, in run self.execute_next_task() File “d:\python\lib\site-packages\locust\user\task.py”, line 315, in execute_next_task self.execute_task(self._task_queue.pop(0)) File “d:\python\lib\site-packages\locust\user\task.py”, line 327, in execute_task task(self) File “D:\thecover_project\api_locust\locust_view\hongya\locust_hy.py”, line 27, in api_community_list with self.client.post(r_url, data=requests_data, catch_response=True, name=r_url, headers=headers) as r: File “d:\python\lib\site-packages\locust\contrib\fasthttp.py”, line 261, in post return self.request(“POST”, path, data=data, **kwargs) File “d:\python\lib\site-packages\locust\contrib\fasthttp.py”, line 189, in request response = self._send_request_safe_mode(method, url, payload=data, headers=headers, **kwargs) File “d:\python\lib\site-packages\locust\contrib\fasthttp.py”, line 109, in _send_request_safe_mode return self.client.urlopen(url, method=method, **kwargs) File “d:\python\lib\site-packages\geventhttpclient\useragent.py”, line 359, in urlopen last_error = self._handle_error(e, url=req.url) File “d:\python\lib\site-packages\geventhttpclient\useragent.py”, line 326, in _handle_error raise reraise(type(e), e, sys.exc_info()[2]) File “d:\python\lib\site-packages\six.py”, line 703, in reraise raise value File “d:\python\lib\site-packages\geventhttpclient\useragent.py”, line 354, in urlopen resp = self._urlopen(req) File “d:\python\lib\site-packages\locust\contrib\fasthttp.py”, line 402, in _urlopen resp = client.request( File “d:\python\lib\site-packages\geventhttpclient\client.py”, line 236, in request sock.sendfile(body) File “d:\python\lib\site-packages\gevent_socket3.py”, line 684, in sendfile return self._sendfile_use_send(file, offset, count) File “d:\python\lib\site-packages\gevent_socket3.py”, line 614, in _sendfile_use_send self._check_sendfile_params(file, offset, count) File “d:\python\lib\site-packages\gevent_socket3.py”, line 653, in _check_sendfile_params raise ValueError(“only SOCK_STREAM type sockets are supported”) ValueError: only SOCK_STREAM type sockets are supported

The same code, using HttpUser does not have this problem。

Environment

  • OS: windows
  • Python version: Python 3.8.3
  • Locust version:locust 1.3.2
  • Locust command line that you ran:
  • Locust file contents (anonymized if necessary):

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
hdzyscommented, Dec 23, 2020

Hmm… is the server doing somethis special in this case? Like returning an upgrade from HTTP to WebSocket?

Your quickest solution is just to use HttpUser, unless you absolutely need the extra load gen performance…

There’s nothing special on the server. er, I’ll use HttpUser or use ‘Get’ method first~ Anyway, thank you all very much!

0reactions
cyberwcommented, Dec 25, 2020

Closing this (feel free to reopen if there is a clear repro case with a publically available server)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create a custom socket client in locust - Stack Overflow
I want to custom a tcp socket client in locust. ... change the __getattribute__ to __getattr__ , get the same type error in...
Read more >
socket — Low-level networking interface — Python 3.11.1 ...
AF_ALG is a Linux-only socket based interface to Kernel cryptography. ... The socket type should be SOCK_STREAM (the default), SOCK_DGRAM , SOCK_RAW or ......
Read more >
Increase performance with a faster HTTP client
Just subclass FastHttpUser instead of HttpUser: from locust import task, FastHttpUser class ... Defaults Content-Type and Accept headers to application/json.
Read more >
Socket Tutorial
Socket types are defined in sys/socket.h . These types-- SOCK_STREAM , SOCK_DGRAM , or SOCK_RAW --are supported by AF_INET and AF_UNIX .
Read more >
Sockets return codes (ERRNOs) - IBM
Error number Message name Socket API type 1 EAI_NONAME GETADDRINFO GETNAMEINFO 1 EDOM All 1 EPERM All
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found