Skip to content

Authorization header not found #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
julzlegaspi opened this issue Jun 22, 2021 · 9 comments
Closed

Authorization header not found #156

julzlegaspi opened this issue Jun 22, 2021 · 9 comments
Labels
duplicate This issue or pull request already exists V3 OData V3

Comments

@julzlegaspi
Copy link

Hello, I was trying to login on SAP B1 but I'm always getting an error 'Authorization header not found'. Here is my code

import pyodata
import requests

SERVICE_URL=https://192.168.xx.xx:50000/b1s/v1

s = requests.Session()
s.verify = False

 s.post(service_url+'/Login', headers={
            "CompanyDB": SAPDEMO,
            "Password": mypassword,
            "UserName": myusername
        })

client = pyodata.Client(SERVICE_URL, s)
print(client)
@phanak-sap phanak-sap added the bug Something isn't working label Jun 25, 2021
@phanak-sap
Copy link
Contributor

phanak-sap commented Jun 25, 2021

Hi @julzpalomiano - from the code it is not possible to know what happened.

Try the script with the pyodata logging enabled.

You can even "go deeper", by enabling logging for the actual http traffic...

from http.client import HTTPConnection
HTTPConnection.debuglevel = 1

logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True

Hope that helps and the problem is apparent. If not, please post the logging information, so far this issue is neither reproducible nor actionable.

@julzlegaspi
Copy link
Author

julzlegaspi commented Jun 26, 2021

Hello @phanak-sap,

I have added your code at the top.

My code:
#pyodata_login.py

import requests
import urllib3
import datetime
import pyodata
from dotenv import dotenv_values
from http.client import HTTPConnection
import logging
HTTPConnection.debuglevel = 1

logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True

config = dotenv_values('.env')

urllib3.disable_warnings()

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

session.post(config['SERVICE_URL']+'/Login', headers={
                "CompanyDB": config['SAP_COMPANY_DB'],
                "Password": config['SAP_PASSWORD'],
                "UserName": config['SAP_USERNAME']
            })

client = pyodata.Client(config['SERVICE_URL'], session)

print(client)

the result:

06/26/2021 10:58:02 AM Creating OData Schema (version: 2)
Traceback (most recent call last):
  File "C:\Users\Julz\Documents\Julz\PYTHON\TCHUB\pyodata_login.py", line 29, in <module>
    client = pyodata.Client(config['SERVICE_URL'], session)
  File "C:\Users\Julz\Documents\Julz\PYTHON\TCHUB\lib\site-packages\pyodata\client.py", line 68, in __new__
    schema = pyodata.v2.model.MetadataBuilder(metadata, config=config).build()
  File "C:\Users\Julz\Documents\Julz\PYTHON\TCHUB\lib\site-packages\pyodata\v2\model.py", line 2589, in build
    schema = Schema.from_etree(edm_schemas, self._config)
  File "C:\Users\Julz\Documents\Julz\PYTHON\TCHUB\lib\site-packages\pyodata\v2\model.py", line 1074, in from_etree
    config.err_policy(ParserError.ENUM_TYPE).resolve(ex)
  File "C:\Users\Julz\Documents\Julz\PYTHON\TCHUB\lib\site-packages\pyodata\v2\model.py", line 70, in resolve
    raise ekseption
  File "C:\Users\Julz\Documents\Julz\PYTHON\TCHUB\lib\site-packages\pyodata\v2\model.py", line 1072, in from_etree
    etype = EnumType.from_etree(enum_type, namespace, config)
  File "C:\Users\Julz\Documents\Julz\PYTHON\TCHUB\lib\site-packages\pyodata\v2\model.py", line 1441, in from_etree
    raise PyODataParserError(
pyodata.exceptions.PyODataParserError: Type None is not valid as underlying type for EnumType - must be one of {'Edm.Byte': [0, 255], 'Edm.Int16': [-32768, 32767], 'Edm.Int32': [-2147483648, 2147483647], 'Edm.Int64': [-9223372036854775808, 9223372036854775807], 'Edm.SByte': [-128, 127]}

any help will be appreciated. Thanks

@phanak-sap
Copy link
Contributor

Hi @julzpalomiano - this is still not enough to determine if it is problem from networking or metadata parsing. You provided the stack trace - that one part of the puzzle - but in the console log you should have logs of actual response returned from the server.

Please check that the response is valid XML document from the $metadata.

A) If not - its hard to investigate not on your computer...You can paste the entire console log with the http request/response logging enabled.. lets see what you see.

B} If yes , then it is not invalid response or networking problem, but trueproblem with parsing of the XML with metadata.

We need the $metadata XML from your service? Either you posted the entire console log - so we know the response now, or you can create your own Gist, or you can create PR to the following repository for this particular purpose - https://github.com/phanak-sap/pyodata-issue-files.

@julzlegaspi
Copy link
Author

Hi @phanak-sap , Thank you for your response. attached the whole console log response. Please let me know if this is enough. Thank you.

pyodata_login_response.txt

@phanak-sap
Copy link
Contributor

Hi @julzpalomiano - ok, it is valid XML response. Could you anyway pls create PR to the https://github.com/phanak-sap/pyodata-issue-files with the XML of the $metadata (you can use the URL https://192.168.xx.xx:50000/b1s/v1$metadata in the browser to see the XML file). Saves the time with the re-formatting/trimming from console output

@julzlegaspi
Copy link
Author

Hi @phanak-sap, I have created a PR already. Thank you for your quick response.

@phanak-sap
Copy link
Contributor

phanak-sap commented Jun 26, 2021

OK thanks, I didn't read properly the console log but it seems I have found the problem.

Your $metadata file declares` <edmx:DataServices m:DataServiceVersion="3.0" m:MaxDataServiceVersion="3.0"> which is Odata Version 3. Pyodata so far supports only Odata v2 - support for v4 (together with v3) is pending; watch #39

If you are not forced to use python, I can recommend our "sibling" library from nodejs world, https://github.com/SAP/odata-library, which does support odata v1-4.

@phanak-sap phanak-sap added V3 OData V3 and removed bug Something isn't working labels Jun 26, 2021
@julzlegaspi
Copy link
Author

Hi @phanak-sap ,

Ok, I understand. I started my project already. right now I am using the http request like.

response = requests.get(config['SERVICE_URL']+'/Items', verify=False)

Thank you for your time looking into my issue :)

@phanak-sap phanak-sap added wontfix This will not be worked on duplicate This issue or pull request already exists and removed wontfix This will not be worked on labels Jun 26, 2021
@phanak-sap
Copy link
Contributor

OK, I am closing the issue as essentially dupe of #39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists V3 OData V3
Projects
None yet
Development

No branches or pull requests

2 participants