3 months ago
I hava a API that has an andpoint where I submit two files, on localhost works on PROD (google cloud) works but on railway the connection just dies
does not give an error log, nothing
just give a 200 with the first line returned with yield
curl command by swagger:
curl -X 'POST' \ 'https://bez-stat-api-dev.up.railway.app/api/v1/analysis/objectives/ai-stream' \
-H 'accept: application/json' \
-H 'Authorization: TOKEN' \
-H 'Content-Type: multipart/form-data' \
-F 'database=@bd.xlsx;type=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' \
-F 'objectives=@objetivos.pdf;type=application/pdf'
RESPONSE:
https://bez-stat-api-dev.up.railway.app/api/v1/analysis/objectives/ai-stream
Request Method
POST
Status Code
200 OK
yield "[DATA] info: Iniciando análise...\n\n"
Pinned Solution
3 months ago
I resolved using flask_sse but IDK why it does not work with stream_with_context function
17 Replies
3 months ago
This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.
Status changed to Open Railway • 3 months ago
3 months ago
I'm able to POST to the URL just fine. I'm not too sure what the issue exactly is, considering you mentioned that the connection dies.
$ curl -X POST https://bez-stat-api-dev.up.railway.app/api/v1/analysis/objectives/ai-stream
{"message": "Token n\u00e3o fornecido"}0x5b62656e5d
I'm able to POST to the URL just fine. I'm not too sure what the issue exactly is, considering you mentioned that the connection dies. ``` $ curl -X POST https://bez-stat-api-dev.up.railway.app/api/v1/analysis/objectives/ai-stream {"message": "Token n\u00e3o fornecido"} ```
3 months ago
curl -X 'POST' \ 'https://bez-stat-api-dev.up.railway.app/api/v1/analysis/objectives/ai-stream' \
-H 'accept: application/json' \
-H 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNjljYzdmNzYxZDFkOTlhNmQ2NDZlYWE2IiwiZXhwIjoxODA4MjcxMDMyfQ.8xz4WZaIIEkJ13UaE976AnUWJuybeYTSSPXtPyxrHz8' \
-H 'Content-Type: multipart/form-data' \
-F 'database=@bd.xlsx;type=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' \
-F 'objectives=@objetivos.pdf;type=application/pdf'
fenol64
curl -X 'POST' \\ '<https://bez-stat-api-dev.up.railway.app/api/v1/analysis/objectives/ai-stream>' \\ \-H 'accept: application/json' \\ \-H 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNjljYzdmNzYxZDFkOTlhNmQ2NDZlYWE2IiwiZXhwIjoxODA4MjcxMDMyfQ.8xz4WZaIIEkJ13UaE976AnUWJuybeYTSSPXtPyxrHz8' \\ \-H 'Content-Type: multipart/form-data' \\ \-F 'database=@bd.xlsx;type=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' \\ \-F 'objectives=@objetivos.pdf;type=application/pdf'
3 months ago
emulated token for you to test it
fenol64
emulated token for you to test it
3 months ago
the database needs to be a .xlsx or csv file and the objectives is a pdf
fenol64
the database needs to be a .xlsx or csv file and the objectives is a pdf
3 months ago
the URL is OK, but when it starts the streaming the connection dies and just returns the first line returned
my api is in python so I have a function that use 'yield' as return
yield "[DATA] info: Iniciando análise...\n\n"
yield "[DATA] A\n\n"
yield "[DATA] bn\n"
it just returns the first one yield "[DATA] info: Iniciando análise...\n\n" and the connection dies
3 months ago
this is how im using
return Response(
stream_with_context(self.generate_ai_objectives_stream()),
mimetype='text/event-stream',
headers={
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'X-Accel-Buffering': 'no'
}
)3 months ago
You need to yield data: instead of [DATA].
For example:
yield "data: Some text stream"3 months ago
You can also reference this:
0x5b62656e5d
You can also reference this: <https://utilities-us-east.up.railway.app/sse>
3 months ago
I edited my code but does not work
same thing:
data: Iniciando análise...
fenol64
I edited my code but does not work same thing: data: Iniciando análise...
3 months ago
it looks like the connection is just not keeping alive
3 months ago
tcp
35.232.42.139:27017
10.217.122.222:56450
Internet
5.5 KB
34ms
NO_SOCKET
just found this log on 'Network Flow Logs'
3 months ago
I'd try putting print/log statements before/after each yield so you can debug where your code (possibly) crashed in deployment logs.
3 months ago
3 months ago
i dont think this is a code error, i think its more a keep the connection to the client
3 months ago
Sorry but not sure how to go about this one.
Railway's SSE sample works perfectly fine. (https://utilities-us-east.up.railway.app/sse)
3 months ago
u have the repo?
3 months ago
I resolved using flask_sse but IDK why it does not work with stream_with_context function
Status changed to Solved brody • 3 months ago
