Playwright get long polling response body - puppeteer

How can you get the response body "stream" of a long polling response in Microsoft Playwright or Puppeteer using page.on('response',myfunction)?
The content type of the response is 'text/event-stream'.
The code stops at await response.body(), is there some solution in Python?
I would be grateful for solutions in other languages as well.

I asked this on the Playwright Github:
This is the anwser of someone responsible for the project (I hope it's alright if I post this here):
"For now subscribing to EventSource.onmessage via javascript is your best bet if you can't wait until the request is finished." He changed my question into a feature request.

Related

Advice on learning email API authentication and JSON in python3

Best solver or fellow problemized,
The context:
The reason I’m asking this question is that I am trying to learn how to automate clinking links in emails with python3. I’ve gone in depth on how to achieve this with selenium but without success. I’ve just heard that this could be possible with API.
I've been trying to find a documentation or explanation for the past 2 hours on how to use something like AHEM - Ad-Hoc Temporary Email Server’s API. https://www.ahem.email/help/api
An hour ago I didn’t know anything and now I know how to call json API with requests and an authentication key. yay me...
The problem:
Now I need to get an authentication token but it asks for content type string and a request body. I’m lost. I’ve used google and youtube but I can only find gmail, reddit and hackernews API documentations which are not much alike I think.
I'm sorry for the vague description of the problem that, quite honestly, resembles my knowledge about the subject. More clarity could be achieved by following the link and taking a look at General: General APIs > POST > Get access token.
The solution?
Does anyone know a good book, video or just plain advice?
Thank you so much in advance!
I hope the answer is not on the front page of Google if you get what I mean.
This should do the job.
import requests
base = 'https://www.ahem.email'
url = f'{base}/api/auth/token'
respone = requests.post(url=url)
if respone.status_code == 200:
token = respone.json()['token']
bearer = f'Bearer {token}'
header = {'Authorization': bearer }
url = f'{base}/api/alive'
print(requests.get(url=url, headers=header).json())

SoundCloud /resolve API endpoint returns JSON instead of JSONP

Related to this question, Soundcloud recently started returning JSON at /resolve instead of JSONP as documented.
Here is a JSBin that demonstrates this issue. IT attempts to resolve a track URL, but the Soundcloud API returns JSON rather than JSONP.
https://jsbin.com/fixabomefe/edit?html,console
(The client ID used there is used in the test environment for an OSS Soundcloud library so it's safe to leak here).
Does anyone (preferably at Soundcloud) know what's going on with the resolve endpoint and jsonp?
Happy to switch to json, but some communication / context about why this change happened would be helpful.
This was due to a bug that made it into production in the last few days. We've just deployed a fix, and it looks like the JSBin is working again. Apologies for the inconvenience!

Is there some kind of http validator?

I am writing a web service in node, and testing it with Postman. I spent a long timing looking for an error. When I finally found it, it turned out to be a simple error formatting the response body, which is json.
If I leave off the final brace in the response body, Postman waits for two minutes, and then reports that it received everything, just fine.
If I leave off the closing quote in the last value in the json, Postman says the server didn't respond, perhaps I should check my security certificates.
I would much rather Postman said "Hey, Buddy, you left off a quote!"
If there some validation service I can talk to? Or a plugin in Postman?
Here there are some validation javascript libraries, you can use:
Validator provides a declarative way of validating javascript objects.
Express-validator acts as an express.js middleware for node-validator.
Meanwhile, Postman got API testing and Collection Runner that can help you through this; which you can write some pre-request script as well as test script for each request.
Also, they got Newman which is a command-line collection runner. It allows you to effortlessly run and test a Postman collection directly from the command-line. It is built with extensibility in mind so that you can easily integrate it with your continuous integration servers and build systems.
I found that Paw worked (https://paw.cloud/). And so far I haven't paid for it.
Where Postman said "check your security certificates," Paw said "we were expecting 376 bytes but you only sent us 312."
Cuts down my time solving the problem a lot!
I use Fiddler for this. It is very good at identifying (with an error message that pops up) problems and bad implementations of the HTTP protocol. Browse the web with it running, and within a few minutes you'll undoubtedly hit a poorly implemented server.
Postman won't be able to handle these cases since it's insulated from poor behavior by the browser's framework.
That's not your problem though.
When I finally found it, it turned out to be a simple error formatting the response body, which is json.
That has absolutely nothing to do with HTTP. HTTP doesn't know or care what your request/response bodies are.
The problem you face is that your API endpoint could be returning whatever it wants. You need a custom solution to your problem, as there is no standard API server in this case.
Most folks will run unit tests that hit common endpoints of your service to ensure they're alive and well.
I should also point out that it should be all but impossible for you to break the JSON response if you're doing it correctly. Sounds like you're serializing JSON manually... never do that, we have JSON serializers for this purpose. Send in an object and let it worry about building the JSON output for you. Otherwise, you'll waste a lot of time on problems like these.

How to make request and send response on the network?

I am working on a JSON project and I basically want to hit on some specified URL with some request and get the response back. I want to know if there are some sites available that can provide me help for request, response on JSON?
Any sort of help is welcome!
Back when "Ajax" was being coined (and well before), we often used the XML HTTP Request object (W3 Schools) but web development is more mature now. Libraries such as jQuery wrap this functionality for easy use (jQuery Ajax)

Executing JSON in Selenium

I need to know the easiest way to execute JSON in a selenium test. An example would be i want to POST { "UserId":"234234" } and test against what is returned. Currently using Advanced REST client chrome app to manually test. I've done a lot of searching on this topic but haven't come across any good examples.
This doesn't sound like it's best solved by selenium. With Selenium you would interact with the form to get that value to post, and handle the subsequent AJAX response / page refresh. If you wish to POST data you should look at a library that performs those types of operations across the wire.
If you are looking for a HTTP library, then Apache has a good one (Java based).