DPCS-team / DPCS

Data Powered Crash Solver
7 stars 17 forks source link

unsupported media type for the example from the apiary #72

Closed MSusik closed 8 years ago

MSusik commented 8 years ago
from urllib2 import Request, urlopen

values = """
  {
    "crash_report": {
      "application": {
        "name": "Google Chrome",
        "version": "48.0.2564.116"
      },
      "system_info": {
        "version": "14.04.1 LTS"
      },
      "exit_code": 1,
      "stderr_output": "Lines from stdErr."
    }
  }
"""

headers = {
  'Content-Type': 'text/json'
}
request = Request('http://54.93.105.103:8000/vd1/crash-reports/', data=values, headers=headers)

response_body = urlopen(request).read()
print response_body

results in

HTTPError: HTTP Error 415: Unsupported Media Type

See http://docs.dpcs.apiary.io/#reference/crashes/crash-report-collection/send-a-new-report

The bug can be also reproduced when you use our client.

patrikos94 commented 8 years ago

I was trying to find a bug on the server for hours, but it turns out it was much simpler... Try these: 1) Make values a dictionary rather than a string(remove """) - values = {...} 2) General code template:

from urllib2 import Request, urlopen
values = {...}
request = Request('http://54.93.105.103:8000/vd1/crash-reports/')
request.add_header('Content-Type', 'application/json')
response = urlopen(request, json.dumps(values))
print response

3) Make sure you are up to date with what kind of data the server expects of you. I've noticed that the database has changed in the last few hours and so has API.

Here is an example of how you can submit a crash report to the server at present:

from urllib2 import Request, urlopen
import json
values = {"crash_report":{"system_info": {"version": "14.04.1 LTS", "packages":"[]", "architecture":"x86"},"exit_code": 1,"stderr_output": "Lines from stdErr."}}
request = Request('http://54.93.105.103:8000/vd1/crash-reports/')
request.add_header('Content-Type', 'application/json')
response = urlopen(request, json.dumps(values))
print response
MSusik commented 8 years ago

We already switched to application/json