Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

308 Redirection when using python 2.7 - adding SSL certificate for https support


#1

Hi All,

I keep running into an issue when trying to get the API working through python 2.7. I have used the exact example code outlined in the API doc, but constantly get a “308 Permanent Redirect” returned from urllib2.urlopen(request),read() when attempting to do anything.
Ive added printouts before this command to check the url, uri, and headers. Everything in the request object seems to be okay.

When I use the exact same login and url/uri via terminal using the example curl command in the api doc, the API is responding fine so it doesn’t seem to be a Testrail issue.

Has anyone else ran into this issue? I can provide code segments if it helps but like I said, I’ve got it copied exactly from the example other than entering my own server, user, and password.

Thanks.


#2

Hi !

Can you give a piece of code that make this kind of error ? It will be easier to help you :slight_smile:


#3

Sure thing. This will be exact code minus italic text for keeping my information private.
When I run this code from the terminal I get a successful response from TestRail:
curl -H “Content-Type: application/json” -u “name@domain.com:pass” “https://server.testrail.io/index.php?/api/v2/get_case/115”

This is my python script:
import os
from testrail import *

client = APIClient(‘http://server.testrail.io/’)
client.user = ‘name@domain.com’
client.password = ‘pass

case = client.send_get(‘get_case/115’ )
print(case)

The error that gets asserted is within the testrail.py script, and it is a “ValueError: No JSON object could be decoded”
So I put a debug printout on the “response” variable to see what is getting sent to json.loads(response)
It turns out the urllib2.HTTPError is getting thrown every time and printing this code block which in turn asserts the json.loads function because it is html and not json format:
59%20AM


#4

Thank you !

I never used the testrail python binding but a point that surprised me is that you use https url in the curl request and http url in the APIClient string. Can you try to use https in the python part ?
client = APIClient(‘https://server.testrail.io/’)


#5

Good catch. It looks like I did it that way since that is how it is displayed on the API documentation for how to do it. When I change my curl to http it spits out he same error I was getting on python(308 redirect) which makes sense now. But when I changed python to https I am now getting a SSL certificate error. I’ve been told before the https is a little iffy with python… wonder if this could be an issue there.
I’m wondering now though, on the API documentation the python example shows using http vs https, but it doesn’t seem to work. Could this be an issue with testrail’s python api script?

Here is the trackback from running my script with https in the APIClient string:


#6

Alright. Looks like this worked now after some googling and adding ssl support thanks to this link.

I added the import ssl as well as these two lines to the testrail.py
41%20AM

Will keep this ticket updated for anyone else that might run into this issue.


#7

Good to hear that :slightly_smiling_face:!