There is no available appointment in the German consulates in my country of residence for a couple of weeks. Can I apply for German visa from a different country in such a case? Is it allowed?
As a general rule, if there is a German consulate in your country of residence, you must apply there. An application may be accepted from a person legally present – but not residing - in another jurisdiction of the consulate where the application is submitted, if the applicant can justify why the application could not be lodged at a consulate in his place of residence. It is for the consulate to appreciate whether the justification presented by the applicant is acceptable. See 2.8 https://ec.europa.eu/home-affairs/sites/homeaffairs/files/policies/borders/docs/c_2010_1620_en.pdf#page23. Unavailability of appointments is unlikely to be accepted as a reason for not applying in your country of residence.