I'm currently working on a bittorrent client in Python.
I'm trying to get the Peer Information from the Tracker for the torrent file to download ubuntu.
I've B-decoded the .torrent file and extracted the info dictionary and created a SHA1 hash from it (exactly as specified in the bittorrent protocol wiki).
I'm using python's requests library to send a HTTP Get request, but when I send the request, I get an error back.
This is my Python GET request for the Ubuntu torrent using the tracker_url as specified in the .torrent file
resp = requests.get('http://torrent.ubuntu.com:6969/announce?info_hash=%3F%19%B1I%F5%3AP%E1O%C0%B7%99%26%A3%91%89n%AB%ABo&peer_id=SAoe4hc3u3du0nepwp1h&compact=1&no_peer_id=0&event=started&port=6883&uploaded=0&downloaded=0&left=1178386432')
In response, I get a Response 200, and the resp.content is
b'd14:failure reason63:Requested download is not authorized for use with this tracker.e'
I'm wondering if someone could tell me what's wrong with my request? Thank you very much!
just look on this answer, a lot of people already asked it
https://stackoverflow.com/a/1019588/4399634
or you can use this bit-torrent client, it's very simple and useful
https://github.com/borzunov/bit-torrent
Related
I have a database of thousands of files online, and I want to check what their status is (e.g. if the file exists, if it sends us to a 404, etc.) and update this in my database.
I've used urllib.request to download files to a python script. However, obviously downloading terabytes of files is going to take a long time. Parallelizing the process would help, but ultimately I just don't want to download all the data, just check the status. Is there an ideal way to check (using urllib or another package) the HTTP response code of a certain URL?
Additionally, if I can get the file size from the server (which would be in the HTTP response), then I can also update this in my database.
If your web server is standards-based, you can use a HEAD request instead of a GET. It returns the same status without actually fetching the page.
The requests module can check the status response of a request.
Just do:
import requests
url = 'https://www.google.com' # Change to your link
response = requests.get(url)
print(response.status_code)
this code shows me 200, so the request has been successful
Sony's website provided a example to use WebSockets to works with their api in Node.js
https://developer.sony.com/develop/audio-control-api/get-started/websocket-example#tutorial-step-3
it worked fine for me. But when i was trying to implement it in Python, it does not seems to work
i use websocket_client
import websocket
ws = websocket.WebSocket()
ws.connect("ws://192.168.0.34:54480/sony/avContent",sslopt={"cert_reqs": ssl.CERT_NONE})
gives
websocket._exceptions.WebSocketBadStatusException: Handshake status 403 Forbidden
but in their example code, there is not any kinds of authrization or authentication
I recently had the same problem. Here is what I found out:
Normal HTTP responses can contain Access-Control-Allow-Origin headers to explicitly allow other websites to request data. Otherwise, web browsers block such "cross-origin" requests, because the user could be logged in there for example.
This "same-origin-policy" apparently does not apply to WebSockets and the handshakes can't have these headers. Therefore any website could connect to your Sony device. You probably wouldn't want some website to set your speaker/receiver volume to 100% or maybe upload a defective firmware, right?
That's why the audio control API checks the Origin header of the handshake. It always contains the website the request is coming from.
The Python WebSocket client you use assumes http://192.168.0.34:54480/sony/avContent as the origin by default in your case. However, it seems that the API ignores the content of the Origin header and just checks whether it's there.
The WebSocket#connect method has a parameter named suppress_origin which can be used to exclude the Origin header.
TL;DR
The Sony audio control API doesn't accept WebSocket handshakes that contain an Origin header.
You can fix it like this:
ws.connect("ws://192.168.0.34:54480/sony/avContent",
sslopt={"cert_reqs": ssl.CERT_NONE},
suppress_origin=True)
I searched but did not found any example showing on how to convert CoAP request or response to HTTP request.
Basically what I want to do is CoAP request POST some data from device to a server which will translate it and do HTTP request POST to other server to be save inside the database.
While the part to save the data is not a major problem right now, I did not managed to find any example script showing how to convert from CoAP to HTTP.
I already looked at coapthon , aiocoap but since aiocoap requires python 3.5,(I use python 2.7) that left me with coapthon. Unfortunately coapthon only has HTTP to CoAP proxy while CoAP to HTTP is still in development.
If anyone know other project regarding this or has any opinion on how to solve this, I am glad if you can share it. Thank you.
That is called Protocol Interoperability. You Need a CoAP - HTTP and HTTP - CoAP proxy that can translate the messages between them.
Here is californium-proxy on GitHub, I am using it already. Here is the example that shows how to use it.
I need to initiate an action on server via sending the HTTP request with GWT-RPC call in body section. I'm completely new in GWT subject so please forgive my lack of knowledge. In Java I was able to perform this action via sending HTTP POST request with proper headers and GWT-RPC in body so I tried to do the same in Python with requests library.
Unfortunately, when sending GWT-RPC call I got response:
//EX[2,1,["com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException/3936916533","This application is out of date, please click the refresh button on your browser. ( Malformed or old RPC message received - expecting version between 5 and 7 )"],0,7]
I read few topics:
Manually generating x-gwt-rpc from Python,
com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException
and as I understood there's no way to send the GWT-RPC call from other platform than Java without some additionall effort. Please correct me and advise if I'm wrong.
Does GAE support Server Sent Events (SSE)?
I tried using SSE but it did not work ,so I switched to Channel API. But still is it possible to implement SSE in GAE ?
I've been trying like crazy to pull this one off but the GAE response is being buffered and compressed.
I'll be very happy if someone has an idea how to write the code/headers so the php file is streamed.
FYI, these are the headers I'm using:
header("Content-Type: text/event-stream; charset=utf-8");
header("Accept-Encoding: identity");
header("Cache-Control: no-cache");
header("Access-Control-Allow-Origin: https://mail.google.com");
header("Access-Control-Allow-Credentials: true");
header('Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"');
[UPDATE]
From: http://grokbase.com/t/gg/google-appengine/15623azjjf/server-sent-events-using-channels-api
What this means in practice is that your stream will not be
"keep-alive" and will close each time one response is sent. Or, if you
implement your server-sent event code server-side as most people do,
it will buffer up all of its responses and finally send them all only
when it terminates.
Please read: https://cloud.google.com/appengine/docs/php/requests#PHP_Responses
Resume: there is no way to do SSE using GAE.