How to build the request for a long poll url for box.com - long-polling

I'm writing a python script that follows the instructions here (https://developers.box.com/using-long-polling-to-monitor-events/) and have run into a snag. I can get the next starting point, but can't seem to get the long poll url.
I am GETting this url (https://api.box.com/2.0/events -X OPTIONS) and I'm using the appropriate authentication header, of course. Based on the instructions, I am looking for the long polling url in the ['entries']['url'] section of the json response to my request.
What I am getting, though, is this: json response:
{'code': 'not_found',
'status': 404,
'request_id': '2064100451fad3cd2cc24',
'type': 'error',
'message': 'Not Found'}
Either I'm not building my url correctly by tacking -X OPTIONS on the end, or something is wrong with the instructions. I'm kinda betting on me not reading the instructions correctly, so any clues would be really appreciated.

I found the answer by Reading The Fine Manual. I interpreted box.com's instructions to indicate I needed to tack "OPTIONS" on the end of the url I sent to them, when what I really needed to do was use the "OPTIONS" http verb.
While CURL wants you to put your HTTP verb at the end of the command line, Python builds a URL in the traditional way. So, if you need to tell box.com you want to use the options verb, you build your url to use options where you would normally use get, put, post, etc.

Related

How to look at http headers sent by safari?

I been trying to debug an issue that ONLY happens on safai, I get:
Bad Request - Invalid Header
http Error 400 The request has an invalid header name
However no matter where I look for in the error console, resources, or timeline I cant look at the headers from said request.
Is there a way to get this information?
You can install http-log and point the Safari URL to localhost:7777 and it will print out what headers Safari is sending.
If you can not change the URL or just want more debugging power you should install a debugging proxy e.g. WebScarab and configure Safari to use that. You get a nice GUI where you can see all the request data: WebScarab GUI
Http-log only prints it to command line.

Hitting API endpoint with GET verb and parameter value=40

I need to hit this endpoint as part of an assessment, I have tried having a looking online and I would ideally like to do this just by using the browser console.
This is my task:
Your task is to write some code (eg. console, html form, javascript, python etc.) to hit 2 API endpoints. You can use any language, framework, tool or library. The result of each endpoint will give you instructions on how to proceed. The first endpoint is /api/Step1 and requires a GET verb and a parameter value=40
I am really trying to understand how to do this but all of the things I have read have not worked.
Any help would be greatly appreciated.
[Postman]
http://i.stack.imgur.com/DA5Oq.png
You should make sure you get the idea of what an API is, and you can read this for the queries.
That said, you are looking to send a GET http request to the url /api/Step1?value=40. You can to this using a tool like Postman on Chrome, but there are other equivalents for other browsers.
If you are using osx/linux, you can look up the command curl on google to see how to do a GET request from the terminal, or check this SO question.
Sending a GET request is quite easy. You can use curl and php for example. If you google it, you can find examples.
Giving a parameter is easy like this: /api/Step1?value=40

Instagram API Returning Invalid Format for Callback_Url Error

I'm using the Instagram API.
I'm trying a simple post for a subscription request, and I keep getting
"Invalid format for 'callback_url'. URL must start with http:// or
https://".
It clearly starts with that.
I can't find anyone online that's running into this same problem.
Tried the post with a clear callback url:
http://api.instagram.com/v1/subscriptions/?client_id={client_id}&client_secret={secret}&object=tag&aspect=media&object_id=skateboarding&callback_url=http://skateparkoftampa.com/spot/instagram_callback.aspx
And with an HTML encoded callback URL:
http://api.instagram.com/v1/subscriptions/?client_id={client_id}&client_secret={secret}&object=tag&aspect=media&object_id=skateboarding&callback_url=http%3A%2F%2Fskateparkoftampa.com%2Fspot%2Finstagram_callback.aspx
Also tried it with both GET and POST, also by letting the API console create the request by simply filling in the parameters fields, etc. I feel like I'm missing something really obvious or something, but I'm stuck. Any ideas?
As sais on Endpoints page:
All endpoints are only accessible via https
You should use your own CLIENT-ID and SECRET-ID and callback url (so don't use API console).
Your callback url may be without https.
Just use link with https:
https://api.instagram.com/v1/subscriptions/
Try examples from this page
You should use POST request to subscribe and unsubscribe, and GET to get list of subscriptions. Please, read documentation accurately.

How can I read this url in Rebol?

when trying to read this kind of url
URL: http://v4.lscache2.c.youtube.com/videoplayback?ip=0.0.0.0&sparams=id,expire,ip,ipbits,itag,algorithm,burst,factor,oc:U0dWSlhTVF9FSkNNNl9QTVhJ&algorithm=throttle-factor&itag=34&ipbits=0&burst=40&sver=3&expire=1275886800&key=yt1&signature=89195E808CB3FBBC7BDE7298A1DC0613D7987F00.D3064112E8F479C523F8DF4FBFDF392CE48167C2&factor=1.25&id=34e01ad39b34b5c9&
I get this error
read/binary url
connecting to: v4.lscache2.c.youtube.com
** User Error: Error. Target url: http://v4.lscache2.c.youtube.com/videoplayback?ip=0.0.0.0&sparams=id,expire,ip,ipbits,
itag,algorithm...
** Near: read/binary url
In Rebol 3 you get:
** Access error: protocol error: "Server error: HTTP/1.1 403 Forbidden"
The message you're getting is Rebol 2's not-so-eloquent way of saying that. (You can also enter it in Firebug and see that using this raw URL does not work.)
I'd imagine that YouTube will only let you get the stream if the requesting HTTP header matches a certain pattern. Among potential things it might look for is a cookie specifically crafted for your session and designed to expire after a certain time.
As far as I understand it YouTube is not too keen on third party downloads of video data. They used to have a get_video API but appear to have disabled it. So you'll either have to fake up a cookie and make them think you're one of their players, or find a service which is friendlier to this sort of application.

How to send a HEAD HTTP request in Python to Amazon S3?

I'm trying to retrieve HTTP HEAD information from a S3 resource using Python. Unfortunately the response always returns a 403 error. I am using code that was suggested
here but unfortunately this does not work for S3 requests. Here is the code (host and key details omitted):
>>> import httplib
>>> conn = httplib.HTTPConnection("www.mybucket.us")
>>> conn.request("HEAD", "/mykey?myparamterers")
>>> res = conn.getresponse()
>>> res.status
>>> 403
The request also sends a signed expiration as part of the query string.
I have also tried using httplib2 but the HEAD REQUEST simply hangs.
If you are using a signed URL, the URL is signed by method (e.g. HEAD or GET). So you will need a different URL for each method.
403 tells you that the request sent was valid (whether it was correct is another story), but that you don't have permission to access the requested page for some reason. At least you know that a valid HTTP request is being sent.
Can you check the server log at all? That might help shed some light on the problem...
I'm not sure about the "HEAD" request either. Can you not use "GET" or "POST" and extract the header yourself? It might be that "HEAD" is not implemented by the library... I am not sure - the documentation I've been able to find by quick googling is woefully inadequate.
403 HTTP code means forbidden. Probably, site administrator disabled this method.
try telnet
telnet www.mybucket.us 80
HEAD http://www.mybucket.us/mykey?myparamterers
Host: www.mybucket.us
<ENTER>
<ENTER>
and watch for server response.
Alternatively, you could use conn.set_debuglevel(1) in python code.
A HEAD request on an AWS S3 pre-signed URL generated for GET will result in a 403 Forbidden response. You can, however, achieve the equivalent of a HEAD request on a pre-signed AWS S3 URL by doing a GET request with the Range header set as follows:
Range: bytes=0-0
here is a code snippet
import requests
response = requests.get(download_url, headers={"Range": "bytes=0-0"})
As shown in the Screen shot, response will have enpty body but will have Hearder info.
https://i.stack.imgur.com/9J99G.png