Flutter SocketIO client does not connect to python SocketIO server - flutter

I have set up a Python SocketIOServer, shown below:
import eventlet
import socketio
sio = socketio.Server()
app = socketio.WSGIApp(sio, static_files={
'/': {'content_type': 'text/html', 'filename': 'index.html'}
})
#sio.event
def connect(sid, environ):
print('connect ', sid)
#sio.event
def message(sid, data):
print('message ', data)
sio.send(data=f"im echoing :{data}", to=sid)
#sio.event
def disconnect(sid):
print('disconnect ', sid)
if __name__ == '__main__':
eventlet.wsgi.server(eventlet.listen(('', 5000)), app)
I tested it with another python socketio client and it worked, the onConnect handler was called and a reply was emitted.
I used socket io dart package to connect to my python server, but I can't make it work.
The code in my flutter app:
#override
void initState() {
socket = IO.io('http://192.168.90.231:5000', <String, dynamic>{
'transports': ['websocket'],
'extraHeaders': {'foo': 'bar'} // optional
});
socket!.onConnect((data) {
log('connected :'+ data);
});
socket!.onError((data) => log("Error: " + data));
socket!.on('event', (data) => log(data));
socket!.onDisconnect((_) => log('disconnect'));
socket!.on('message', (msg) => log("message from server: "+msg));
socket!.send(['test']);
log("listeners are set.");
}
What I get logged in my server is something like polling, every few seconds:
192.168.90.151 - - [11/Apr/2022 03:14:12] "GET /socket.io/?EIO=3&transport=websocket HTTP/1.1" 400 195 0.000999
(3088) accepted ('192.168.90.151', 50132)
192.168.90.151 - - [11/Apr/2022 03:14:17] "GET /socket.io/?EIO=3&transport=websocket HTTP/1.1" 400 195 0.000000
(3088) accepted ('192.168.90.151', 50136)
192.168.90.151 - - [11/Apr/2022 03:14:22] "GET /socket.io/?EIO=3&transport=websocket HTTP/1.1" 400 195 0.000000
(3088) accepted ('192.168.90.151', 50138)
192.168.90.151 - - [11/Apr/2022 03:14:27] "GET /socket.io/?EIO=3&transport=websocket HTTP/1.1" 400 195 0.000000
(3088) accepted ('192.168.90.151', 50140)
192.168.90.151 - - [11/Apr/2022 03:14:32] "GET /socket.io/?EIO=3&transport=websocket HTTP/1.1" 400 195 0.000000
....
But my listeners (neither in server nor in client) are not called.

The issue was that my client and server socket.io library versions didn't match.
It was mentioned in the documentation but I didn't pay attention to it:
socket.io-client-dart Socket.io Server
v0.9.* ~ v1.* v2.*
v2.* v3.* & v4.*
I upgraded my client version to socket_io_client: ^2.0.0-beta.4-nullsafety.0 and it got fixed.

Related

Cannot connect to to FastAPI with WebSocket in Flutter. 403 forbidden / code 1006

So I've been trying for while to establish a websocket connection between my flutter app and FastAPI.
I believe the problem lies in Flutter.
So far i've tried the flutter packages socket_io_client, web_socket_channel and websocket_manager to no awail.
I suspect it might have to do with the app architecture maybe... bit at a loss atm.
Here is the flutter errors:
I/onListen(26110): arguments: null
I/EventStreamHandler(26110): 🔴 event sink
I/onListen(26110): arguments: null
I/EventStreamHandler(26110): 🔴 event sink
W/System.err(26110): java.net.ProtocolException: Expected HTTP 101 response but was '403 Forbidden'
W/System.err(26110): at okhttp3.internal.ws.RealWebSocket.checkUpgradeSuccess$okhttp(RealWebSocket.kt:185)
W/System.err(26110): at okhttp3.internal.ws.RealWebSocket$connect$1.onResponse(RealWebSocket.kt:156)
W/System.err(26110): at okhttp3.RealCall$AsyncCall.run(RealCall.kt:140)
W/System.err(26110): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/System.err(26110): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/System.err(26110): at java.lang.Thread.run(Thread.java:923)
I/EventStreamHandler(26110): ✅ sink is not null
I/flutter (26110): websocket closed
Im aware it says the 403 forbidden came from my API, though i know websocket connection is possible, as i've tested it with javascript.
here is the log from the API:
DEBUG | websockets.protocol:__init__:244 - server - state = CONNECTING
DEBUG | websockets.protocol:connection_made:1340 - server - event = connection_made(<_SelectorSocketTransport fd=484 read=polling write=<idle, bufsize=0>>)
DEBUG | websockets.protocol:data_received:1412 - server - event = data_received(<422 bytes>)
DEBUG | websockets.server:read_http_request:237 - server < GET /11 HTTP/1.1
DEBUG | websockets.server:read_http_request:238 - server < Headers([('authorization', 'Bearer *JWTTOKEN*'), ('upgrade', 'websocket'), ('connection', 'Upgrade'), ('sec-websocket-key', 'zytoCsWVlcmsKghL5XFEdA=='), ('sec-websocket-version', '13'), ('host', '10.0.2.2:8000'), ('accept-encoding', 'gzip'), ('user-agent', 'okhttp/4.3.1')])
INFO | uvicorn.protocols.websockets.websockets_impl:asgi_send:198 - ('127.0.0.1', 50772) - "WebSocket /11" 403
DEBUG | websockets.server:write_http_response:256 - server > HTTP/1.1 403 Forbidden
DEBUG | websockets.server:write_http_response:257 - server > Headers([('Date', 'Fri, 09 Apr 2021 11:10:11 GMT'), ('Server', 'Python/3.7 websockets/8.1'), ('Content-Length', '0'), ('Content-Type', 'text/plain'), ('Connection', 'close')])
DEBUG | websockets.server:write_http_response:267 - server > body (0 bytes)
DEBUG | websockets.protocol:fail_connection:1261 - server ! failing CONNECTING WebSocket connection with code 1006
DEBUG | websockets.protocol:connection_lost:1354 - server - event = connection_lost(None)
DEBUG | websockets.protocol:connection_lost:1356 - server - state = CLOSED
DEBUG | websockets.protocol:connection_lost:1365 - server x code = 1006, reason = [no reason]
I have all the WebSocket code in a Class that is beeing 'provided', I.E WebSocketState:
return runApp(
MultiProvider(
providers: [
Provider<AuthenticationState>(
create: (_) => new AuthenticationState(),
),
Provider<WebSocketState>(
create: (_) => new WebSocketState(),
),
],
child: MyApp(),
),
);
WebSocketState:
class WebSocketState {
final _socketMessage = StreamController<Message>();
Sink<Message> get getMessageSink => _socketMessage.sink;
Stream<Message> get getMessageStream => _socketMessage.stream;
WebsocketManager socket;
bool isConnected() => true;
void connectAndListen(int userId) async {
var token = await secureStorage.read(key: 'token');
socket = WebsocketManager(
'ws://10.0.2.2:8000/$userId', {'Authorization': 'Bearer $token'});
socket.onClose((dynamic message) {
print('websocket closed');
});
// Listen to server messages
socket.onMessage((dynamic message) {
print("Message = " + message.toString());
});
// Connect to server
socket.connect();
}
void dispose() {
_socketMessage.close();
socket.close();
}
}
the connectAndListen method is called in the first/main page after user has authenticated, then in other Pages the websocket is beeing used.
#override
void didChangeDependencies() {
super.didChangeDependencies();
Provider.of<WebSocketState>(context, listen: false).connectAndListen(
Provider.of<AuthenticationState>(context, listen: false).id);
}
API websocket 'class':
websocket_notifier.py
from enum import Enum
import json
from typing import List
class SocketClient:
def __init__(self, user_id: int, websocket: WebSocket):
self.user_id = user_id
self.websocket = websocket
class WSObjects(Enum):
Message = 0
class Notifier:
def __init__(self):
self.connections: List[SocketClient] = []
self.generator = self.get_notification_generator()
async def get_notification_generator(self):
while True:
message = yield
await self._notify(message)
async def push(self, msg: str):
await self.generator.asend(msg)
async def connect(self, user_id: int, websocket: WebSocket):
await websocket.accept()
self.connections.append(SocketClient(user_id, websocket))
def remove(self, websocket: WebSocket):
client: SocketClient
for x in self.connections:
if x.websocket == websocket:
client = x
self.connections.remove(client)
async def _notify(self, message: str):
living_connections = []
while len(self.connections) > 0:
# Looping like this is necessary in case a disconnection is handled
# during await websocket.send_text(message)
client = self.connections.pop()
await client.websocket.send_text(message)
living_connections.append(client)
self.connections = living_connections
async def send(self, user_id: int, info: WSObjects, json_object: dict):
print("WS send running")
msg = {
"info": info,
"data": json_object
}
print("connections count: " + str(len(self.connections)))
for client in self.connections:
if client.user_id == user_id:
print("WS sending msg to ${client.user_id}")
await client.websocket.send_text(json.dumps(msg))
break
notifier = Notifier()
API main:
from fastapi import FastAPI
from websocket_notifier import notifier
from starlette.websockets import WebSocket, WebSocketDisconnect
app = FastAPI()
#app.get("/")
async def root():
return {"message": "Root"}
#app.websocket("/ws/{user_id}")
async def websocket_endpoint(user_id: int, websocket: WebSocket):
await notifier.connect(user_id, websocket)
try:
while True:
data = await websocket.receive_text()
await websocket.send_text(f"Message text was: {data}")
except WebSocketDisconnect:
notifier.remove(websocket)
#app.on_event("startup")
async def startup():
# Prime the push notification generator
await notifier.generator.asend(None)
Any ideas what Im doing wrong? (the other flutter websocket packages I've used virutally In the same way as the one I showed)
through lots of testing i finally found a way to get websockets to work with my flutter app and fastapi.
https://github.com/tiangolo/fastapi/issues/129
Had to try a bit of different things from that issue thread. But endend up with using python-socketio. I had to use a lower version of python-socketio to be compatible with the newest flutter socket_io_client package.
For those who have the same problem, please also check #2639. Prefix of the APIRouter does not work in websocket decorator.

Response 411 Length Required in Gatling

I'm starting in Gatling. I have 411 status and don't understand why.
Response DefaultHttpResponse(decodeResult: success, version: HTTP/1.1)
HTTP/1.1 411 Length Required
Connection: close
Date: Tue, 13 Feb 2018 16:07:51 GMT
Server: Kestrel
Content-Length: 0
19:07:53.083 [gatling-http-thread-1-2] DEBUG org.asynchttpclient.netty.channel.ChannelManager - Closing Channel [id: 0x5f14313e, L:/10.8.1.89:52767 - R:blabla.com:5000]
19:07:53.107 [gatling-http-thread-1-2] INFO io.gatling.commons.validation.package$ - Boon failed to parse into a valid AST: -1
java.lang.ArrayIndexOutOfBoundsException: -1
...
19:07:53.111 [gatling-http-thread-1-2] WARN io.gatling.http.ahc.ResponseProcessor - Request 'HTTP Request createCompany' failed: status.find.is(200), but actually found 411
19:07:53.116 [gatling-http-thread-1-2] DEBUG io.gatling.http.ahc.ResponseProcessor -
My code:
package load
import io.gatling.core.scenario.Simulation
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
class LoadScript extends Simulation{
val httpConf = http
.baseURL("http://blabla.com:5000")
.authorizationHeader("Bearer 35dfd7a3c46f3f0bc7a2f06929399756029f47b9cc6d193ed638aeca1306d")
.acceptHeader("application/json, text/plain,")
.acceptEncodingHeader("gzip, deflate, br")
.acceptLanguageHeader("ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7")
.userAgentHeader("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36")
val basicLoad = scenario("BASIC_LOAD").exec(BasicLoad.start)
setUp(
basicLoad.inject(rampUsers(1) over (1 minutes))
.protocols(httpConf))
}
object BasicLoad {
val start =
exec(
http("HTTP Request createCompany")
.post("/Companies/CreateCompanyAndStartTransaction")
.queryParam("inn","7733897761")
.queryParam("ogrn","5147746205041")
.check(status is 200, jsonPath("$.id").saveAs("idCompany"))
)
}
When you are not sending message-body you need to add
.header("Content-Length", "0") as workaround.
I have similar issue. I'm running my tests on two environments and a difference is in application infrastructure.
Tests are passing on Amazon AWS but getting HTTP 411 on Azure. So looks like the issue is not in Gatling itself.
This issue has been also well answered by Gatling team at the and of this chat:
https://groups.google.com/forum/#!topic/gatling/mAGzjzoMr1I
I've just upgraded Gatling from 2.3 to 3.0.2. They wrote their own HTTP client and it sends now content-length: 0 except one case described in this bug:
https://github.com/gatling/gatling/issues/3648
so if you avoid using httpRequest() with method type passed as string e.g:
exec(http("empty POST test").httpRequest("POST","https://gatling.io/"))
and use post() as you do:
exec(
http("HTTP Request createCompany")
.post("/Companies/CreateCompanyAndStartTransaction")...
or
exec(
http("HTTP Request createCompany")
.httpRequest(HttpMethod.POST, "/Companies/CreateCompanyAndStartTransaction")
then upgrade Gatling to 3.0.2 is enough. Otherwise you need to wait for Gatling 3.0.3

jobProgressToken: Jira (Zephyr) Rest API

I am using Jira (Zephyr) rest calls to create Test Cycle and add Tests cases into it. According to information mentioned here1 if I use this rest call to add tests to Cycle then as a response I will get JobProgressToken. JobProgressToken is nothing but will tell the progress of Test Case addition in Test Cycle.
Now the problem which I am facing is I am not getting any output from this JobProgressToken. I tried firing the GET rest call using the format mentioned but I am getting empty response.
Can somebody please explain how to use this JobProgressToken to get the Progress of my task?
I want to verify that the tests which I added to Cycle are added susccessfully or not?
Just ysterday I had the same issue. ZAPI documentation is really confusing. I found the following solution:
GET request for retrieving a job progress has the following form: http://jira/rest/zapi/latest/execution/jobProgress/0001498157843923-5056b64fdb-0001
where 0001498157843923-5056b64fdb-0001 is a value of the particular jobProgressToken
Right after getting a jobProgressToken as a result of some async operation, my code is waiting for the progress to became 1 (it is groing up from zero to 1)
//get the job progress token as a result of some async operation invocation
String jobProgressToken = new JSONObject(zapiResponse).getString("jobProgressToken");
waitAsyncJobToBeCompleted(jobProgressToken);
void waitAsyncJobToBeCompleted(String jobProgressToken) {
double jobProgress;
do {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
LOG.error("Error while try to make the thread sleeping 500ms. " + e.getLocalizedMessage());
e.printStackTrace();
}
jobProgress = getJobProgress(jobProgressToken);
} while (Double.compare(jobProgress, 1) <0);
private double getJobProgress(String jobProgressToken) {
URI uri = makeUriFromString(String.format(
GET_GetJobProgress, //Get request pattern
connectionParameters.getJiraUrl(),//host
jobProgressToken)); //parameters
HttpResponse response = executeHttpRequestWithResponse(new HttpGet(uri));
String zapiResponse = null;
try {
zapiResponse = EntityUtils.toString(response.getEntity());
LOG.trace("ZAPI RESPONSE: " + zapiResponse);
EntityUtils.consumeQuietly(response.getEntity()); //cleanup the HTTP response
double progress = new JSONObject(zapiResponse).getDouble("progress");
LOG.debug("Job progress: " + progress);
return progress;
} catch (IOException e) {
String err = String.format("Error while getting Zephyr API response: %s",
e.getLocalizedMessage());
LOG.fatal(err);
throw new RestApiException(err, e);
} catch (JSONException e) {
String err = String.format("Error while retrieving the job progress from JSON: %s\n%s",
zapiResponse, e.getLocalizedMessage());
LOG.fatal(err);
throw new RestApiException(err, e);
}
}
This is all magic :)
Following two logs: 1st for cloning test cycle, 2nd for deleting
ZephyrClient.invokeHttpPost - URI=http://jira/rest/zapi/latest/cycle JSON payload={"projectId": "13795","clonedCycleId": 2643,"name": "ZAPI client test","description": "Created With ZAPI client unit test","versionId": "-1"}
ZephyrClient.cloneTestCycle - RESPONSE JSON: {"jobProgressToken":"0001498218783350-5056b64fdb-0001"}
ZephyrClient.executeHttpRequestWithResponse - HTTP REQUEST: GET http://jira/rest/zapi/latest/execution/jobProgress/0001498218783350-5056b64fdb-0001 HTTP/1.1
ZephyrClient.executeHttpRequestWithResponse - HTTP RESPONSE: HTTP/1.1 200 OK
ZephyrClient.getJobProgress - ZAPI RESPONSE: {"timeTaken":"0 min, 1 sec","stepMessage":"","summaryMessage":"","errorMessage":"","progress":0.56,"message":"","stepLabel":"","stepMessages":[]}
ZephyrClient.getJobProgress - Job progress: 0.56
ZephyrClient.executeHttpRequestWithResponse - HTTP REQUEST: GET http://jira/rest/zapi/latest/execution/jobProgress/0001498218783350-5056b64fdb-0001 HTTP/1.1
ZephyrClient.executeHttpRequestWithResponse - HTTP RESPONSE: HTTP/1.1 200 OK
ZephyrClient.getJobProgress - ZAPI RESPONSE: {"timeTaken":"0 min, 1 sec","stepMessage":"","summaryMessage":"","errorMessage":"","progress":0.98,"message":"","stepLabel":"","stepMessages":[]}
ZephyrClient.getJobProgress - Job progress: 0.98
ZephyrClient.executeHttpRequestWithResponse - HTTP REQUEST: GET http://jira/rest/zapi/latest/execution/jobProgress/0001498218783350-5056b64fdb-0001 HTTP/1.1
ZephyrClient.executeHttpRequestWithResponse - HTTP RESPONSE: HTTP/1.1 200 OK
ZephyrClient.getJobProgress - ZAPI RESPONSE: {"timeTaken":"0 min, 2 sec","stepMessage":"","summaryMessage":"","errorMessage":"","progress":0.98,"message":"","stepLabel":"","stepMessages":[]}
ZephyrClient.getJobProgress - Job progress: 0.98
ZephyrClient.executeHttpRequestWithResponse - HTTP REQUEST: GET http://jira/rest/zapi/latest/execution/jobProgress/0001498218783350-5056b64fdb-0001 HTTP/1.1
ZephyrClient.executeHttpRequestWithResponse - HTTP RESPONSE: HTTP/1.1 200 OK
ZephyrClient.getJobProgress - ZAPI RESPONSE: {"timeTaken":"0 min, 3 sec","stepMessage":"","summaryMessage":"","errorMessage":"","progress":1.0,"message":"Cycle ZAPI client test created successfully.","stepLabel":"","stepMessages":[]}
ZephyrClient.getJobProgress - Job progress: 1.0
ZephyrClient.executeHttpRequestWithResponse - HTTP REQUEST: GET http://jira/rest/zapi/latest/cycle?projectId=13795&versionId=-1 HTTP/1.1
ZephyrClient.executeHttpRequestWithResponse - HTTP RESPONSE: HTTP/1.1 200 OK
ZephyrClient.invokeHttpDelete - URI=http://jira/rest/zapi/latest/cycle/2727
ZephyrClient.deleteTestCycle - RESPONSE JSON: {"jobProgressToken":"0001498218815183-5056b64fdb-0001"}
ZephyrClient.executeHttpRequestWithResponse - HTTP REQUEST: GET http://jira/rest/zapi/latest/execution/jobProgress/0001498218815183-5056b64fdb-0001 HTTP/1.1
ZephyrClient.executeHttpRequestWithResponse - HTTP RESPONSE: HTTP/1.1 200 OK
ZephyrClient.getJobProgress - ZAPI RESPONSE: {"timeTaken":"0 min, 0 sec","stepMessage":"","summaryMessage":"","errorMessage":"","progress":1.0,"message":"{\"success\":\"Cycle ZAPI client test успешно удален\"}","stepLabel":"","stepMessages":[]}
ZephyrClient.getJobProgress - Job progress: 1.0
ZephyrClient.executeHttpRequestWithResponse - HTTP REQUEST: GET http://jira/rest/zapi/latest/cycle?projectId=13795&versionId=-1 HTTP/1.1
ZephyrClient.executeHttpRequestWithResponse - HTTP RESPONSE: HTTP/1.1 200 OK
P.S. This is not about how it should be done.
This is about how does it work for me ;)

Scala - printing specific fields in each line from a file

While learning, I'm trying to read a web log and extract few fields from it. The web log will be like below
147.172.225.10 - 16401 [16/Sep/2013:23:52:35 +0100] "GET /KBDOC-00057.html HTTP/1.0" 200 11761 "http://www.newbie.com" "test F20L"
147.172.225.10 - 16401 [16/Sep/2013:23:52:35 +0100] "GET /theme.css HTTP/1.0" 200 12353 "http://www.newbie.com" "test Mobile Browser Sorrento F20L"
23.53.29.101 - 32693 [16/Sep/2013:23:49:50 +0100] "GET /KBDOC-00035.html HTTP/1.0" 200 9337 "http://www.newbie.com" "test Mobile Browser i3"
And I need to extract just the IP address and User id(3rd field) from the logs and print as
147.172.225.10/16401
147.172.225.10/16401
23.53.29.101/32693
If I have to use map or flatMap, could someone help me how and let me know if there is a better way to accomplish it. Thanks in advance !!
For each line(as string) in the weblog, you can use split method on the basis of a blank character, and after splitting it will return an array of string, with that, you can extract the required values.
lines map { line =>
val lineArray = line.split(" ")
lineArray(0), lineArray(2)
}
Thanks everyone, I used below to get the required results.
map(line => line.split(' ')).map(fields => (fields(0) + "/" + fields(2)))

Cherrypy _cp_dispatch strange behaviour with url without trailing slash: POST then GET

I am testing CherryPy with _cp_dispatch.
However, when I send 1 single post, _cp_dispatch is called twice, not once. First for the expected post then a second time with a get: Why?
The code:
import os
import cherrypy
class WebServerApp:
def __init__(self):
self.index_count = 0
self.cpdispatch_count = 0
def __del__(self):
self.exit()
def _cp_dispatch(self, vpath):
self.cpdispatch_count += 1
cherrypy.log.error('_cp_dispatch: ' + str(vpath) + ' - index count:' + str(self.cpdispatch_count))
if len(vpath) == 0:
return self
if len(vpath) == 2:
vpath.pop(0)
cherrypy.request.params['id'] = vpath.pop(0)
return self
return vpath
#cherrypy.expose
def index(self, **params):
try:
self.index_count += 1
cherrypy.log.error('Index: received params' + str(params) + ' - index count:' + str(self.index_count))
except Exception as e:
cherrypy.log.error(e.message)
def exit(self):
cherrypy.log.error('Exiting')
exit.exposed = True
ws_conf = os.path.join(os.path.dirname(__file__), 'verybasicwebserver.conf')
if __name__ == '__main__':
cherrypy.quickstart(WebServerApp(), config=ws_conf)
The config file:
[global]
server.socket_host = "127.0.0.1"
server.socket_port = 1025
server.thread_pool = 10
log.screen = True
log.access_file = "/Users/antoinebrunel/src/Rankings/log/cherrypy_access.log"
log.error_file = "/Users/antoinebrunel/src/Rankings/log/cherrypy_error.log"
The post with request:
r = requests.post("http://127.0.0.1:1025/id/12345")
The log results showing that cp_dispatch is called 3 times: 1 at startup and twice for the post
pydev debugger: starting (pid: 5744)
[30/Sep/2014:19:16:29] ENGINE Listening for SIGUSR1.
[30/Sep/2014:19:16:29] ENGINE Listening for SIGHUP.
[30/Sep/2014:19:16:29] ENGINE Listening for SIGTERM.
[30/Sep/2014:19:16:29] ENGINE Bus STARTING
[30/Sep/2014:19:16:29] _cp_dispatch: ['global', 'dummy.html'] - _cp_dispatch count:1
[30/Sep/2014:19:16:29] ENGINE Started monitor thread '_TimeoutMonitor'.
[30/Sep/2014:19:16:29] ENGINE Started monitor thread 'Autoreloader'.
[30/Sep/2014:19:16:29] ENGINE Serving on http://127.0.0.1:1025
[30/Sep/2014:19:16:29] ENGINE Bus STARTED
[30/Sep/2014:19:16:34] _cp_dispatch: ['id', '12345'] - _cp_dispatch count:2
127.0.0.1 - - [30/Sep/2014:19:16:34] "POST /id/12345 HTTP/1.1" 301 117 "" "python-requests/2.4.0 CPython/3.4.1 Darwin/13.3.0"
[30/Sep/2014:19:16:34] _cp_dispatch: ['id', '12345'] - _cp_dispatch count:3
[30/Sep/2014:19:16:34] Index: received params{'id': '12345'} - index count:1
127.0.0.1 - - [30/Sep/2014:19:16:34] "GET /id/12345/ HTTP/1.1" 200 - "" "python-requests/2.4.0 CPython/3.4.1 Darwin/13.3.0"
Any idea of why _cp_dispatch is called twice for a single post?
-- EDIT
I'm suspecting some 301 redirection going on internally since it appears in the log.
In cherrypy, an internal redirection occurs when the url does not end with a slash.
https://cherrypy.readthedocs.org/en/3.3.0/refman/_cprequest.html#cherrypy._cprequest.Request.is_index
There are 2 ways to resolve the "problem":
First is obviously posting to http://example.com/id/12345/
Second is adding the following to the configuration file:
tools.trailing_slash.on = False
https://cherrypy.readthedocs.org/en/3.2.6/concepts/config.html