Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm hoping someone else has seen this issue and knows what the problem might be. I have written some python 3.4 code to read the config.xml file of a job in from Jenkins using the requests 2.7.0 package and the URL format:
http://jenkins/job/<job name>/config.xml

All is good but it takes a good 9-12 seconds for the page to be retrieved. If I put that URL in a browser the result is instantaneous so I don't think the server or network is the problem here. I have also tried to use the pyJenkins package but again any request takes the same amount of time.

I've obviously done a Google search on this but nothing seems relevant which is suggesting I'm doing something wrong as opposed to a bug in the package itself.

I used the following code to get the page:
Python
import requests

# Get a list of all the jobs on the system
a = requests.get('http://jenkins-server/api/json', params={'pretty':'true'},
                 auth=("username", "password"))

I have also tried to access web pages on the net that do not require authentication, http and https sites and other internal web servers that we have but they are all slow.

Anyone have any ideas why this is happening or suggest how to fix it?
Posted
Updated 22-Jun-17 22:02pm
Comments
Xiao Ling 24-Jul-15 4:34am    
Have you tried urllib2?
DelboyJay001 23-Jun-17 3:45am    
It could be something to do with the DNS lookup that I have found before. Are you running the python code on Windows or Linux? Can you try using the IP address and see if that speeds things up?

1 solution

Try this and see if it works. You could have a DNS issue so try an IP address instead of a DNS name and check if it is faster. Failing that, there is a known problem with proxy detection in the requests library even if you have your system setup to bypass which I imagine you have in this case.

import requests

session = requests.Session()
session.trust_env = False

response = session.get('http://jenkins-server/api/json', params={'pretty':'true'},
                 auth=("username", "password")))


This code snippet comes from here and talks about the same problem:

python - requests: how to disable / bypass proxy - Stack Overflow[^]
 
Share this answer
 
Comments
Richard Deeming 23-Jun-17 9:25am    
Talking to yourself is the first sign of madness!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900