We have a Django website that interacts with Salesforce custom object named Temp Contact (API: Temp_Contact__c). When I try to login to website, I receive this error in the terminal-

AttributeError: 'HttpResponse' object has no attribute 'query'

But my colleagues are able to login/signup without this error. Only on my system this issue occurs. We are using simple-salesforce==0.73.0 package for integration. I have this package installed in my machine. The line of code that causes the error-

    sf1 = salesforceconnection()
    sf21 = sf1.query("SELECT Id, Name, Temp_Contact_LastName__c, Temp_Contact_Password__c, Temp_Contact_Active__c, Temp_Contact_Mobile__c, Temp_Contact_Head__c FROM Temp_Contact__c WHERE Temp_Contact_Email__c ='{0}'".format(uname))

The salesforceconnection-

    #Used to establish connection with Salesforce NPSP
    def salesforceconnection():
         sf = Salesforce(instance_url='https://test.salesforce.com', session_id='')
         sfconnect = Salesforce(username='sfdcuser@happy.com.happ',
         return HttpResponse('Something went wrong. Please try after sometime')
       return sfconnect

I put sf1 in print statement and I see that sf1 returns status_code=200. The complete error flow-

SF1=<HttpResponse status_code=200, "text/html; charset=utf-8">

Internal Server Error: /happy/loginpage.html Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 42 r response = get_response(request) File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py", line 187, in ponse response = self.process_exception_by_middleware(e, request) File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py", line 185, in ponse response = wrapped_callback(request, *callback_args, **callback_kwargs) File "C:\Users\user\Desktop\Myhappy\myhappy.org\home\views.py", line 220, in happylogin

sf21 = sf1.query("SELECT Id, Name, Temp_Contact_LastName__c, Temp_Contact_Password__c, Temp_Contact_Active__ ary_Contact_Mobile__c,

Temp_Contact_Head__c FROM Temp_Contact__c WHERE Temp_Contact_Email__c ='{0}'".format(unam AttributeError: 'HttpResponse' object has no attribute 'query' [02/Nov/2017 13:23:28] "POST /happy/loginpage.html HTTP/1.1" 500 71539

Why is that error thrown and how can it be resolved?

  • I'd say that your method salesforceconnection() is not returning the right object type. and that's why it cannot find query. Can you share (with the details masked, of course) your code for salesforceconnection() ? – Sergio Alcocer Nov 2 '17 at 9:45
  • @SergioAlcocer I have edited the question with more details. Please let me why it is failing. Note: My colleagues are able to access it without any error. – SFDC Developer Nov 2 '17 at 9:59
  • taking into account your first error HttpResponse object has no attribute 'query' and your except: it seems to me that its throwing an exception and that's why you cannot continue. Check on the user login attempts to see if your attempt is there and the reason for the failure. (invalid password, invalid IP, etc) – Sergio Alcocer Nov 2 '17 at 10:10
  • Well, I did enter correct login credentials. But let me tell you, I do get 'Stronger security is required' error very often. Can that be a reason to not able to establish connection? – SFDC Developer Nov 2 '17 at 10:32
  • Have a look at help.salesforce.com/articleView?id=000221207&type=1 and search for Stronger security is required, It seems that it might be related to TLS 1.0 connections, etc. – Sergio Alcocer Nov 2 '17 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.