Python request response is empty












0















My code below successfully pulled data from https://permit.pcta.org/application/



import requests
from tabulate import tabulate
import time

'''outputs '''
PERMITS =

'''input'''
url = 'https://permit.pcta.org/manage/ajax/onload-ajax.php'


headers = {
'User-Agent': 'Mozilla/5.0',
'X-Requested-With': 'XMLHttpRequest'
}

r = requests.get(url, headers=headers)
print(r.content)


However, the response is empty. I am positive I didn't change anything in my code, so I can't explain why the website's response is now different.



As a sanity check below are snippets of the element and response from my browser.



html element



response










share|improve this question

























  • What is your question? Hitting that URL returns a 404 for me.

    – Matt Morgan
    Nov 21 '18 at 2:01











  • why the code I copied is not working anymore. The URL works, just tried it.

    – chacos
    Nov 21 '18 at 2:13











  • Did you tried to specify an Accept header with Application/JSON value?

    – Jacobo Tapia
    Nov 21 '18 at 2:42













  • Just tried that. I get the same error mentioned above.

    – chacos
    Nov 21 '18 at 3:13











  • One reason is you may use post method to get data. And the another reason should be login required before access

    – kcorlidy
    Nov 21 '18 at 6:30
















0















My code below successfully pulled data from https://permit.pcta.org/application/



import requests
from tabulate import tabulate
import time

'''outputs '''
PERMITS =

'''input'''
url = 'https://permit.pcta.org/manage/ajax/onload-ajax.php'


headers = {
'User-Agent': 'Mozilla/5.0',
'X-Requested-With': 'XMLHttpRequest'
}

r = requests.get(url, headers=headers)
print(r.content)


However, the response is empty. I am positive I didn't change anything in my code, so I can't explain why the website's response is now different.



As a sanity check below are snippets of the element and response from my browser.



html element



response










share|improve this question

























  • What is your question? Hitting that URL returns a 404 for me.

    – Matt Morgan
    Nov 21 '18 at 2:01











  • why the code I copied is not working anymore. The URL works, just tried it.

    – chacos
    Nov 21 '18 at 2:13











  • Did you tried to specify an Accept header with Application/JSON value?

    – Jacobo Tapia
    Nov 21 '18 at 2:42













  • Just tried that. I get the same error mentioned above.

    – chacos
    Nov 21 '18 at 3:13











  • One reason is you may use post method to get data. And the another reason should be login required before access

    – kcorlidy
    Nov 21 '18 at 6:30














0












0








0








My code below successfully pulled data from https://permit.pcta.org/application/



import requests
from tabulate import tabulate
import time

'''outputs '''
PERMITS =

'''input'''
url = 'https://permit.pcta.org/manage/ajax/onload-ajax.php'


headers = {
'User-Agent': 'Mozilla/5.0',
'X-Requested-With': 'XMLHttpRequest'
}

r = requests.get(url, headers=headers)
print(r.content)


However, the response is empty. I am positive I didn't change anything in my code, so I can't explain why the website's response is now different.



As a sanity check below are snippets of the element and response from my browser.



html element



response










share|improve this question
















My code below successfully pulled data from https://permit.pcta.org/application/



import requests
from tabulate import tabulate
import time

'''outputs '''
PERMITS =

'''input'''
url = 'https://permit.pcta.org/manage/ajax/onload-ajax.php'


headers = {
'User-Agent': 'Mozilla/5.0',
'X-Requested-With': 'XMLHttpRequest'
}

r = requests.get(url, headers=headers)
print(r.content)


However, the response is empty. I am positive I didn't change anything in my code, so I can't explain why the website's response is now different.



As a sanity check below are snippets of the element and response from my browser.



html element



response







python python-3.x python-requests






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 23:13









Spacedman

73.2k995169




73.2k995169










asked Nov 21 '18 at 1:56









chacoschacos

42




42













  • What is your question? Hitting that URL returns a 404 for me.

    – Matt Morgan
    Nov 21 '18 at 2:01











  • why the code I copied is not working anymore. The URL works, just tried it.

    – chacos
    Nov 21 '18 at 2:13











  • Did you tried to specify an Accept header with Application/JSON value?

    – Jacobo Tapia
    Nov 21 '18 at 2:42













  • Just tried that. I get the same error mentioned above.

    – chacos
    Nov 21 '18 at 3:13











  • One reason is you may use post method to get data. And the another reason should be login required before access

    – kcorlidy
    Nov 21 '18 at 6:30



















  • What is your question? Hitting that URL returns a 404 for me.

    – Matt Morgan
    Nov 21 '18 at 2:01











  • why the code I copied is not working anymore. The URL works, just tried it.

    – chacos
    Nov 21 '18 at 2:13











  • Did you tried to specify an Accept header with Application/JSON value?

    – Jacobo Tapia
    Nov 21 '18 at 2:42













  • Just tried that. I get the same error mentioned above.

    – chacos
    Nov 21 '18 at 3:13











  • One reason is you may use post method to get data. And the another reason should be login required before access

    – kcorlidy
    Nov 21 '18 at 6:30

















What is your question? Hitting that URL returns a 404 for me.

– Matt Morgan
Nov 21 '18 at 2:01





What is your question? Hitting that URL returns a 404 for me.

– Matt Morgan
Nov 21 '18 at 2:01













why the code I copied is not working anymore. The URL works, just tried it.

– chacos
Nov 21 '18 at 2:13





why the code I copied is not working anymore. The URL works, just tried it.

– chacos
Nov 21 '18 at 2:13













Did you tried to specify an Accept header with Application/JSON value?

– Jacobo Tapia
Nov 21 '18 at 2:42







Did you tried to specify an Accept header with Application/JSON value?

– Jacobo Tapia
Nov 21 '18 at 2:42















Just tried that. I get the same error mentioned above.

– chacos
Nov 21 '18 at 3:13





Just tried that. I get the same error mentioned above.

– chacos
Nov 21 '18 at 3:13













One reason is you may use post method to get data. And the another reason should be login required before access

– kcorlidy
Nov 21 '18 at 6:30





One reason is you may use post method to get data. And the another reason should be login required before access

– kcorlidy
Nov 21 '18 at 6:30












1 Answer
1






active

oldest

votes


















1














It looks like you are missing the Referer in the headers, I added Referer to your code and it worked:



headers = {
'User-Agent': 'Mozilla/5.0',
'X-Requested-With': 'XMLHttpRequest',
'Referer': 'https://permit.pcta.org/application/'
}


Not sure why it worked without it before, probably an api has changed, or you were passing Referer somewhere else in your code.






share|improve this answer
























  • Thank you! I found this out earlier by copying every header my browser used to make the request. Still not sure how it was working before without the Referer header.

    – chacos
    Nov 26 '18 at 23:14











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404286%2fpython-request-response-is-empty%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














It looks like you are missing the Referer in the headers, I added Referer to your code and it worked:



headers = {
'User-Agent': 'Mozilla/5.0',
'X-Requested-With': 'XMLHttpRequest',
'Referer': 'https://permit.pcta.org/application/'
}


Not sure why it worked without it before, probably an api has changed, or you were passing Referer somewhere else in your code.






share|improve this answer
























  • Thank you! I found this out earlier by copying every header my browser used to make the request. Still not sure how it was working before without the Referer header.

    – chacos
    Nov 26 '18 at 23:14
















1














It looks like you are missing the Referer in the headers, I added Referer to your code and it worked:



headers = {
'User-Agent': 'Mozilla/5.0',
'X-Requested-With': 'XMLHttpRequest',
'Referer': 'https://permit.pcta.org/application/'
}


Not sure why it worked without it before, probably an api has changed, or you were passing Referer somewhere else in your code.






share|improve this answer
























  • Thank you! I found this out earlier by copying every header my browser used to make the request. Still not sure how it was working before without the Referer header.

    – chacos
    Nov 26 '18 at 23:14














1












1








1







It looks like you are missing the Referer in the headers, I added Referer to your code and it worked:



headers = {
'User-Agent': 'Mozilla/5.0',
'X-Requested-With': 'XMLHttpRequest',
'Referer': 'https://permit.pcta.org/application/'
}


Not sure why it worked without it before, probably an api has changed, or you were passing Referer somewhere else in your code.






share|improve this answer













It looks like you are missing the Referer in the headers, I added Referer to your code and it worked:



headers = {
'User-Agent': 'Mozilla/5.0',
'X-Requested-With': 'XMLHttpRequest',
'Referer': 'https://permit.pcta.org/application/'
}


Not sure why it worked without it before, probably an api has changed, or you were passing Referer somewhere else in your code.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 26 '18 at 3:05









svetlannnkasvetlannnka

814




814













  • Thank you! I found this out earlier by copying every header my browser used to make the request. Still not sure how it was working before without the Referer header.

    – chacos
    Nov 26 '18 at 23:14



















  • Thank you! I found this out earlier by copying every header my browser used to make the request. Still not sure how it was working before without the Referer header.

    – chacos
    Nov 26 '18 at 23:14

















Thank you! I found this out earlier by copying every header my browser used to make the request. Still not sure how it was working before without the Referer header.

– chacos
Nov 26 '18 at 23:14





Thank you! I found this out earlier by copying every header my browser used to make the request. Still not sure how it was working before without the Referer header.

– chacos
Nov 26 '18 at 23:14




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404286%2fpython-request-response-is-empty%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?